zoukankan      html  css  js  c++  java
  • 解决yii2 禁用layout时AppAsset不加载资源的问题

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

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

    <?php
    moduleassetsAppAsset::register($this);
    $this->context->layout = false;
    ?>
    
    <?php $this->beginPage() ?> <-- 必需 -->
    <html>
    
    <-- 视图代码块 -->
    
    <body>
    <?php $this->beginBody() ?> <-- 必需 -->
    
    <-- 视图代码块 -->
    
    <?php $this->endBody() ?> <-- 必需 -->
    </body>
    </html>
    <?php $this->endPage() ?> <-- 必需 -->
  • 相关阅读:
    etcd+confd管理nginx
    k8s基础
    nginx配置总结
    Golang相关
    docker基础
    celery结合django使用配置
    常用算法
    python3和paramiko安装
    git使用总结
    Linux系统入门实操经验分享
  • 原文地址:https://www.cnblogs.com/musings/p/7605965.html
Copyright © 2011-2022 走看看