1., Folder structure
We assume that your Yii2 module is located at
The assets are at
2., Set an alias to your assets in your Module.php in your module (/yii-base-folder/modules/YOUR-YII-MODULE-FOLDER/Module.php)
class Module extends \yii\base\Module
public $controllerNamespace = 'app\modules\MY-MODULE\controllers';
public function init()
'@MY-MODULE-assets' => __DIR__ . '/assets'
3., Put your asset class into your assets folder to setup your "assets bundle"
We name a bunch of assets "assets bundle". Here you declare your files and make it accessible to your view.
class MyModuleAsset extends AssetBundle
// the alias to your assets folder in your file system
public $sourcePath = '@yiipass-assets';
// finally your files..
public $css = [
public $js = [
// that are the dependecies, for makeing your Asset bundle work with Yii2 framework
public $depends = [
4., Now you can access your assets from your view
We assume that your view's index.php file is located at /yii-base-folder/modules/YOUR-MODULE/views/ANY-VIEWS-SUBFOLDER/index.php
// that class is usually used, if you work with html in your view.
// here comes your Yii2 asset's class!
Some <strong>HTML</strong> my <i>friend..</i> :)
The path in your project's directory will be:
Also the PHP asset class will be copied from your module's folder:
Don't forget to not modify the files at /YOUR-Yii2-PROJECT/web/assets/3598bbc6/ manually, because they're created automatically by the Yii2 framework.
6., Learn more
The "The Definitive Guide to Yii 2.0" is mostly the best first place to learn about Yii2. So you find more detailed information about the assets functionality at the assets chapter. I recommend also to read the excellent PHP class comments in the Yii2 core. Like f.e. /YOUR-Yii2-PROJECT/vendor/yiisoft/yii2/web/AssetBundle.php. Yii2 is one of the few OpenSource projects where the PHP code itself can often lead you to your goals.