passing php variable from controller to javascript function in the head of a view

yeah sure, just echo the javascript: <?php echo '<script>var myPhpVariable = "'. $my_var . '";</script>'; ?>


or just set in your controller your variables

eg - in the controller

$data['newvar'] = $myvar_in_the_controller;

and then in the view in the javascript

<?php echo $newvar ?>