passing php variable from controller to javascript function in the head of a view November 6, 2022 by Tarik yeah sure, just echo the javascript: <?php echo '<script>var myPhpVariable = "'. $my_var . '";</script>'; ?>