官方文档也有介绍:http://www.yiichina.com/doc/guide/2.0/structure-assets#bower-npm-assets
安装 iziToast
- 安装
iziToast.js
这个前端资源
composer require bower-asset/izitoast
或者添加composer.json
然后 update:"bower-asset/izitoast": "^1.1"
,安装之后大概目录结构如下:

- 新建
IziToastAsset.php
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| <?php
namespace app\assets;
use yii\web\AssetBundle;
class IziToastAsset extends AssetBundle
{
public $sourcePath = '@bower/izitoast/dist';
public $js = [
'js/iziToast.min.js'
// more plugin Js here
];
public $css = [
'css/iziToast.min.css'
// more plugin CSS here
];
}
|
- view层使用:
\app\assets\IziToastAsset::register($this)
安装 semantic ui
bower install semantic-ui
或者 composer require bower-asset/semantic-ui
(可能是npm-asset/semantic-ui
) 会安装在vendor/bower目录下- 创建一个assets资源,比如在
/frontend/assets
下创建一个SemanticAsset.php
文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| <?php
namespace frontend\assets;
use yii\web\AssetBundle;
class SemanticAsset extends AssetBundle
{
public $sourcePath = '@bower/semantic';
public $css = [
'dist/semantic.min.css'
];
public $js = [
'dist/semantic.min.js'
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstap\BootstrapAsset'
]
}
|
- 注册资源,main.php中使用
1
2
3
4
5
| <?php
// views/layouts/main.php
use frontend\assets\SemanticAsset;
SemanticAsset::register($this);
|