Search code examples
phpjquery-uiyii2assetbundle

How to add jQuery UI to an Asset Bundle


I have the following asset bundle and i would like to add jQuery UI as part of it as well. How can I do it?

<?php
namespace app\assets;

use yii\web\AssetBundle;

class AdminAsset extends AssetBundle
{
    public $basePath = '@webroot/assets-admin';
    public $baseUrl = '@web/assets-admin';

    public $css = [
        'css/common.css',
        'css/animations.css',
        'css/editor.css',
        'css/form.css',
        'css/fileupload.css',
        'css/template.css',
        'css/icons.css',
    ];
    public $js = [
        'js/libs/modernizr.js',
        'js/script.js'
    ];
    public $depends = [
        'yii\web\JqueryAsset',
        'yii\web\YiiAsset',
    ];
} 

Solution

  • At first install official JUI Extension for Yii 2.

    Then add yii\jui\JuiAsset to list of dependent assets:

    public $depends = [
        'yii\jui\JuiAsset',
        ...       
    ];
    

    yii\web\JqueryAsset in this case is not required because JuiAsset already has it in dependencies list so it will be included as well.