YII2前端资源Assets

来源:互联网 发布:有百合网源码卖 编辑:程序博客网 时间:2024/05/18 02:32

在手册里面我们看到如下的解释

也就是说在我们的应用(高级模版在frontend/backend)下面的assets目录下定义的又一个文件叫做

AppAsset.php在这个文件里面你可以定义你的js或者css等文件

<?phpnamespace app\assets;use yii\web\AssetBundle;class AppAsset extends AssetBundle{    public $basePath = '@webroot';    public $baseUrl = '@web';    public $css = [        'css/site.css',    ];    public $js = [    ];    public $depends = [        'yii\web\YiiAsset',        'yii\bootstrap\BootstrapAsset',    ];}

这里basePath是/usr/local/nginx/html/这种web的根目录
这里baseUrl是http://frontend.blog.com这个url的地址

当然YII已经集成了bootstrap前段框架你可以集成其他的
我们简单使用的话,这些我们都不要

在我们的/frontend/assets/AppAsset.php
把我们的资源加载进去
$depends我们可以保留为空不写

在我们的视图文件里面我们要这样写

use frontend\assets\AppAsset;AppAsset::register($this);然后在<head></head>中间加上<?php $this->head() ?>就OK了
0 0
原创粉丝点击