解决yii2 禁用layout时AppAsset不加载资源的问题

来源:互联网 发布:文华期货软件 编辑:程序博客网 时间:2024/06/05 06:05

大王派我来巡山_site:http://blog.csdn.net/wang78699425/article/details/52369841

最近由于项目(yii2 的一个项目)需要,登录页面不需要使用布局(layout),使用单独的页面,然后我就在登录视图里面加了一行代码$this->context->layout = false 来禁用layout,同时使用 module\assets\AppAsset::register($this) 来加载资源(css、js等),刷新页面,发现css、js全都未加载进来,懵逼~。
后来调试半天,发现是通过$this->beginPage() 等来引入的,只有在视图上加入几个必需的代码,资源才会引入,代码如下:

<?phpmodule\assets\AppAsset::register($this);$this->context->layout = false;?><?php $this->beginPage() ?> <-- 必需 --><html><-- 视图代码块 --><body><?php $this->beginBody() ?> <-- 必需 --><-- 视图代码块 --><?php $this->endBody() ?> <-- 必需 --></body></html><?php $this->endPage() ?> <-- 必需 -->

0 0