码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2017-09-28 12:54:27      阅读:484      评论:0      收藏:0      [点我收藏+]

标签:roc   false   调试   刷新   reg   yii2   yii   code   sdn   

大王派我来巡山_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() 等来引入的,只有在视图上加入几个必需的代码,资源才会引入,代码如下:

<?php
module\assets\AppAsset::register($this);
$this->context->layout = false;
?>

<?php $this->beginPage() ?> <-- 必需 -->
<html>

<-- 视图代码块 -->

<body>
<?php $this->beginBody() ?> <-- 必需 -->

<-- 视图代码块 -->

<?php $this->endBody() ?> <-- 必需 -->
</body>
</html>
<?php $this->endPage() ?> <-- 必需 -->

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

标签:roc   false   调试   刷新   reg   yii2   yii   code   sdn   

原文地址:http://www.cnblogs.com/musings/p/7605965.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!