Month: September 2014

Yii assets folder Javascript import

There are two ways in Yii to import the javascript file

$oow_url =Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.modules.oow.assets'));

Yii::app()->clientScript->registerScriptFile($oow_url.'\js\oow.js') ;

Yii::app()->getClientScript()->registerScriptFile($oow_url.'/js/oow.js', CClientScript::POS_END);

I was having following line in my javascript file
document.getElementById("Product_serial_number").value='75787';

When I was using


Yii::app()->clientScript->registerScriptFile($oow_url.'\js\oow.js')
;

I was getting error as Uncaught Object Type

However

When I tried

Yii::app()->getClientScript()->registerScriptFile($oow_url.'/js/oow.js', CClientScript::POS_END);

It worked fine.

I guess the best way to import javascript file in Yii from assets folder is


Yii::app()->getClientScript()->registerScriptFile($oow_url.'/js/oow.js', CClientScript::POS_END);

Advertisements