Include Javascript And Css

Including Javascript And Css




 $baseUrl = Yii::app()->baseUrl; 

  $cs = Yii::app()->getClientScript();

  $cs->registerScriptFile($baseUrl.'/js/yourscript.js');

  $cs->registerCssFile($baseUrl.'/css/yourcss.css');

Thank you.

How to include the css files in header and the .js files in footer of the site?

Styles will be registered a head tag.

To place js at desired position you need to pass second parameter of registerScriptFile() method

Example:

[size="2"]


$cs->registerScriptFile($baseUrl.'/js/yourscript.js', CClientScript::POS_END);

[/size]

[size=“2”]There’s a convenient practice also to configure default scripts position this way (put it to ‘components’ section of your config file):[/size]

[size="2"]




'clientScript' => array(

	'class' => 'CClientScript',

    'coreScriptPosition' => CClientScript::POS_END,

    'defaultScriptFilePosition' => CClientScript::POS_END,

    'defaultScriptPosition' => CClientScript::POS_READY,

),



[/size]