首页 > 移动平台 > 详细

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

时间:2017-09-28 12:10:32      阅读:252      评论:0      收藏:0      [点我收藏+]

大王派我来巡山_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不加载资源的问题

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!