解決yii2 禁用layout時AppAsset不載入資源的問題

來源:互聯網
上載者:User

標籤: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() 等來引入的,只有在視圖上加入幾個必需的代碼,資源才會引入,代碼如下:

<?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() ?> <-- 必需 -->

解決yii2 禁用layout時AppAsset不載入資源的問題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.