I am using
<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>
for register jquery in Yii 1 top of script but in page added last of scripts? why?
I am using
<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>
for register jquery in Yii 1 top of script but in page added last of scripts? why?
You can use coreScriptPosition for this.
Directly from the docs:
Where the scripts registered using registerCoreScript or registerPackage will be inserted in the page. This can be one of the CClientScript::POS_* constants. Defaults to CClientScript::POS_HEAD.
Use like this:
$cs = Yii::app()->clientScript;
$cs->coreScriptPosition = CClientScript::POS_HEAD;
$cs->registerCoreScript('jquery');
Another useful link to read on this. (Read the comments too)
--Edit--
You can tell Yii where to put the script in the method:
Yii::app()->clientScript->registerScript(string $id, string $script, integer $position=NULL, array $htmlOptions=array ( ));
The $position variable will be the position of the script on your page.
And can be any of these:
CClientScript::POS_HEAD : the script is inserted in the head section right before the title element.CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.CClientScript::POS_END : the script is inserted at the end of the body section.CClientScript::POS_LOAD : the script is inserted in the window.onload() function.CClientScript::POS_READY : the script is inserted in the jQuery's ready function.CClientScript, my bad.