Search code examples
yiiyii-extensions

How can I use the NLSClientScript extension in Yii?


How can I use the extension http://www.yiiframework.com/extension/nlsclientscript/ ?

I tried this:

config/main.php:

'clientScript' => array( 
'class' => 'ext.NLSClientScript',

views/layouts/main.php:

$cs = Yii::app()->getClientScript();
$systemJsPath = Yii::app()->getAssetManager()->publish(
     Yii::getPathOfAlias('system.web.js' ), false, -1, false );
$cs->registerScriptFile('jquery');
$cs->registerScriptFile( $systemJsPath . '/custom.js');
$cs->registerScriptFile( $systemJsPath . '/ext/plugins/jquery.form.js');

But it doesn't work. jQuery is not loaded.


Solution

  • Jquery is known as a core script in Yii and should be registered using CClientScript::registerCoreScript.

    In your example:

    $cs->registerCoreScript('jquery');
    

    The short names for all core scripts are listed in YII_PATH/web/js/packages.php.