Jquery Script Insert Into Head Tag

How can I insert




<script src="jquery.js"></script>



or any other scripts in head tag of Yii?

Thankx

To prevent including jQuery more than once, you should consider using the following somewhere in your view or action:




Yii::app()->clientScript->registerCoreScript('jquery');



This will automatically place the script tag into the head of the page for you.

See here for more methods from that class.

Thanks it really worked! :)

i would like to ask on how to add other scripts. I’ve tried to do this, is there something wrong about this?





    Yii::app()->clientScript->registerScript('export_script', 'exporting.js', CClientScript::POS_HEAD);



it won’t execute.

Assuming that your file is already web accessible, you probably want to use registerScriptFile().

If it’s not yet web accessible (it’s in the protected folder), you need to publish it first. This will give you the URL that you need.