passing php variable from controller to javascript function in the head of a view
问题 I would pass two php variables from a codeigniter controller to a javascript function located to the head of my view. is it possible to do such thing? 回答1: yeah sure, just echo the javascript: <?php echo '<script>var myPhpVariable = "'. $my_var . '";</script>'; ?> 回答2: 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 ?> 回答3: I have been developing a page that requires