28

yii\bootstrap\BootstrapAsset is not loading bootstrap.js, and such elements as "modal" and others are not working.

class AppAsset extends AssetBundle {
    public $basePath = '@webroot';

    public $baseUrl = '@web';

    public $css = [    
        /* theme */
        'css/site.css',

        /* jasny bootstrap */
        'public/jasny/css/jasny-bootstrap.min.css',

        /* font awesome */
        'public/font-awesome-430/css/font-awesome.min.css',

        /* font roboto */
        'public/fonts/roboto/roboto.css',

        /* Data Tables */
        'public/datatables/extensions/integration/bootstrap/3/dataTables.bootstrap.css',  
    ];

    public $js = [    
        /* jasny bootstrap  */
        'public/jasny/js/jasny-bootstrap.min.js',

        /* Data Tables  */
        'public/datatables/datajs.js',
        'public/datatables/media/js/jquery.dataTables.min.js',
        'public/datatables/extensions/integration/bootstrap/3/dataTables.bootstrap.js',               
    ];

    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset',
    ];    
}

Here is screen of libraries, bootstrap.js is missing there.

arogachev
  • 33,150
  • 7
  • 114
  • 117
ccdiego5
  • 666
  • 1
  • 7
  • 15

5 Answers5

31

If you look at the content of BootstrapAsset bundle, you will see that there is no bootstrap.js:

class BootstrapAsset extends AssetBundle
{
    public $sourcePath = '@bower/bootstrap/dist';
    public $css = [
        'css/bootstrap.css',
    ];
}

For bootstrap.js another asset bundle exists and it's called BootstrapPluginAsset:

class BootstrapPluginAsset extends AssetBundle
{
    public $sourcePath = '@bower/bootstrap/dist';
    public $js = [
        'js/bootstrap.js',
    ];
    public $depends = [
        'yii\web\JqueryAsset',
        'yii\bootstrap\BootstrapAsset',
    ];
}

The full class name with namespace is: yii\bootstrap\BootstrapPluginAsset.

It's included automatically when you use js dependent bootstrap widgets such as yii\bootstrap\Modal, etc.

arogachev
  • 33,150
  • 7
  • 114
  • 117
  • 1
    in $depends i need to call ¿BootstrapPluginAsset? for the 'js/bootstrap.js'? – ccdiego5 May 19 '15 at 18:17
  • 2
    Yes, you can include it in `depends` section of your asset bundle. – arogachev May 19 '15 at 18:20
  • What could I do if I want to know the hierarchical dependency of an `AssetBundle`? In other words, in this case, I want to know where `BootstrapPluginAsset` is regarded as a dependency? @arogachev – SaidbakR Sep 30 '16 at 17:18
27

You can try it:

class AppAsset extends AssetBundle{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
    'css/mystyle.css',
];
public $js = [

];
public $depends = [
    'yii\web\YiiAsset',
    'yii\bootstrap\BootstrapPluginAsset',
];
}
mzk10k
  • 394
  • 4
  • 4
9

when you add dependency

 public $depends = [
        'yii\bootstrap\BootstrapAsset',
    ];

its only add bootstrap css

while you add

 public $depends = [
     'yii\bootstrap\BootstrapPluginAsset',
    ];

its add bootstrap css as well as js

Kalpesh Desai
  • 1,405
  • 15
  • 17
2

You can do this in the main configuration file (config/web.php):

'components' => [
    'assetManager' => [
        'bundles' => [
            'yii\bootstrap\BootstrapAsset' => [
                'js' => ['js/bootstrap.js'],
            ],
        ],
    ],
],
Roman Grinyov
  • 222
  • 2
  • 5
  • 20
0

You can try this in AppAsset.php

class AppAsset extends AssetBundle{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
  'css/mystyle.css',
];
public $js = [

];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapPluginAsset',
];
}

and also change in you config/main.php

'components' => [
'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapAsset' => [
            'js' => ['js/bootstrap.min.js'],
        ],
    ],
],
],

I have tried these steps that will solve my problem thats to all for your comment

Shamsi786
  • 129
  • 1
  • 10