March 25 2016

Yii2 always load bootstrap.js

Tagged Under :

Yii
Normally on Yii2 wouldn’t always load the bootstrap.js on our Web App, only when you use js dependent bootstrap widgets such as yii\bootstrap\Modal and etc.

You need add some code on the framework to always load the bootstrap.js on the Web App.
Open the file on the following directory:
vendor\yiisoft\yii2-bootstrap\BootstrapAsset.php
Open the file you will see the code as below:
class BootstrapAsset extends AssetBundle 
{
    public $sourcePath = '@bower/bootstrap/dist';
    public $css = [
        'css/bootstrap.css',
    ];
}
And then, You may add the public $js as the following:
class BootstrapAsset extends AssetBundle
{
    public $sourcePath = '@bower/bootstrap/dist';
    public $css = [
        'css/bootstrap.css',
    ];
    public $js = [
        'js/bootstrap.js',
    ];
}
Refresh you Website, you will found that bootstrap.js was load on every page.

Make a Comment

*

code