yii2引入js和css
2015-05-11 17:30 youxin 阅读(1400) 评论(0) 编辑 收藏 举报assets/AppAsset.php
public $css = [
'css/site.css',
'css/font/css/font-awesome.min.css',
'css/doc.css',
];
public $js = [
'js/core/app.js',
];
布局文件中有
AppAsset::register($this);
http://www.yiichina.com/question/344
http://www.yiichina.com/topic/5604
//输出url
<a href="<?= Url::to(['/users/login/login','id'=>5,'mark'=>true]) ?>" >登录 </a>
以上等同于
<a href="/users/login/login?id=5&mark=true" >登录 </a>
//注册css
①css代码
<?php
$css=<<<CSS
.title{
color:blue;
}
CSS;
$this->registerCss($css,View::POS_END); //注册css代码 ,并置于最后面,避免被覆盖
?>
②注册css样式文件
<?php
$this->registerCssFile('@web/css/mystyle.css');
?>
//注册js
①js代码
<?php
$js=<<<JS
alert(123);
JS;
$this->registerJs($js,View::POS_HEAD); //注册JS代码 ,并置于最前面
?>
② js文件
<?php
$this->registerJsFile('@web/js/myJs.js')
?>
参考:http://www.cnblogs.com/sheapchen/p/3939767.html
解决引入顺序:
use app\assets\AppAsset;
use yii\bootstrap\BootstrapAsset;
AppAsset::register($this);
$this->registerCssFile("@web/css/login.css",[
'depends'=>[BootstrapAsset::className()]
]);
关键是depends,参考:http://www.yiiframework.com/doc-2.0/guide-output-client-scripts.html
The option depends
is specially handled. It specifies which asset bundles this CSS file depends on. In this case, the dependent asset bundle is BootstrapAsset. This means the CSS file will be added afterthe CSS files in BootstrapAsset.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
2014-05-11 《深度探索c++对象模型》chapter1关于对象对象模型
2013-05-11 UML关联和依赖区别
2012-05-11 java 一个Icon接口实现的程序
2012-05-11 JFrame 刷新问题
2012-05-11 Java Web Start 简介