noob question, how to load jquery ui?

I’ve loaded jQuery with

<?php Yii::app()->clientScript->registerCoreScript(‘jquery’); ?>

How can I load jQuery UI ?

Not sure if this is the best way to do this, but I looked through the assets folder to find what jquery scripts came with Yii and load them like this:



$cs->registerScriptFile(Yii::app()->baseUrl . '/assets/c67c137/jquery.metadata.js', CClientScript::POS_HEAD);

$cs->registerScriptFile(Yii::app()->baseUrl . '/assets/c67c137/jquery.swapimage.min.js', CClientScript::POS_HEAD);

$cs->registerScriptFile(Yii::app()->baseUrl . '/assets/js/main.js', CClientScript::POS_HEAD);

Using this approach you can just put whatever javascript file you want in the assets folder and load it this way.

If anyone knows a better way to load the jquery plugins that come with Yii I would love to know it.

You should not use the assets directory like that. jQuery UI will be published automatically (to the assets folder) if there’s a CJui… widget in the view. For more details, look in the CJuiWidget source (framework/zii/widgets/jui/CJuiWidget.php), methods resolvePackagePath() and registerCoreScripts().


But what if I want to use a jquery-ui plugin that does not include in the official jquery-ui.js?

In this case copy your jquery-ui in js folder or another and publish it with AssetManager, or the whole folder

I ran into the same scenario where I did not require the need to load a Yii JUI Widget so this is what I implemented. Doing it this way I ensure that I always have the latest release of JUI that Yii bundles with the framework.

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






Please not the last line where I am calling a downloaded UI theme that I have placed in my css/ folder. Yii is bundled with the base JUI theme only.

Hope this helps. :)

Now, with 1.1.4 version, zii.vendors.jui doesn’t exist. What we need to do else?


Thanks, but Is the same like Yii::getPathOfAlias(‘system.web.js.source.jui’) ?

No. It registers the script, not just getting a path.

and how could I register css files that belongs to the jQuery UI?

Did not work for me. I’m using 1.1.3. The script does not get included.

jquery.ui option was added in 1.1.4, but it doesn’t register css files bundled with “ui” somehow


CSS files are going separately, cause of themes that could be different, depending on their css / images

I’ve used jQuery UI “redmond” theme

<?php Yii::app()->clientScript->registerCoreScript( 'jquery.ui' ); ?>

<?php $redmond = Yii::app()->assetManager->publish( Yii::app()->basePath . '/resources/jquery.ui/redmond/' ); ?>

<?php Yii::app()->clientScript->registerCssFile( $redmond . '/jquery-ui-1.8.5.custom.css', 'screen' ); ?>