1.资源管理器中引入静态资源css,js
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Main backend application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
'css/bootstrap.css'
];
public $js = [
'js/bootstrap.js',
'js/jquery.js'
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
2.引入的静态资源会被发布到当前程序下的静态资源的文件夹 下的assets文件夹中
3.项目中引入并使用
3.1引入use backend\assets\AppAsset;
3.2使用AppAsset::register($this);
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use backend\assets\AppAsset;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<?= $content ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>