Asset bundles
Assets in Yii2 are managed through an asset bundle. An asset bundle in Yii2 is simply a class that declares all the assets that we want to use in our application, and resides within the assets/
directory of our application, usually within the AppAsset.php
file that declares an AppAsset
class that extends yii\web\AssetBundle
. Since our default application comes within a pre-defined AppAsset
class, let's take a look at what is already defined in that file.
<?php namespace app\assets; use yii\web\AssetBundle; class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ 'css/site.css', '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js' ]; public $js = [ ]; public $depends = [ 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', ]; }
Our example asset bundle file declares several public properties...