June 23 2013

Yii include/preload yiigridview javascript

Tagged Under :

Yii
Normally we include Javascript in our application in Yii is below script
Yii::app()->getClientScript()->registerScriptFile('jquery.js');	
But, now we need include yiigridview.js script file in our application. Because it was generate by Yii and it located at assets folder. So above example cannot used.

In here, we need to call getAssetManager() to get the assets folder url and folder name generated by Yii.
Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.widgets.assets'));
The above example will get the gridview path from the assets folder.

After that you need to call registerScriptFile() class to include the files you want.

Below example will show you how to use it.
$assetsScriptUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.widgets.assets'));
Yii::app()->getClientScript()->registerScriptFile($assetsScriptUrl .'/gridview/jquery.yiigridview.js');

Make a Comment

*

code