Search code examples
yiiyui

How can I use YUI 3 in Yii?


How can I use YUI 3 in Yii framework? I searched on the internet and I couldn't find anything


Solution

  • You can load any javascript library with Yii. You can add it to your layout (most likely protected/views/layouts/main.php) like so:

    <?php Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl.'/js/yui/yui-min.js', CClientScript::POS_HEAD); ?>
    

    Assuming your YUI library is located at js/yui/yui-min.js. This will now load that js file into the head section of every view that uses that layout.

    You can then use it as per normal. Keep in mind that jQuery is built into Yii, so you may have compatibility issues between jQuery and YUI. Check out this post on the jQuery website for more info.

    I would also recommend having a look at the Yii CClientScript documentation here. The CClientScript class manages JavaScript and CSS stylesheets for views within Yii.