Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 BootstrapAsset is not loading bootstrap.js

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.

like image 344
ccdiego5 Avatar asked May 19 '15 13:05

ccdiego5


Video Answer


2 Answers

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.

like image 157
arogachev Avatar answered Sep 23 '22 02:09

arogachev


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', ]; } 
like image 39
mzk10k Avatar answered Sep 21 '22 02:09

mzk10k