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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s