想去掉layout , 使用 $layout = false 之后,在view中连自己加的 asset 都被去掉了 [ 新手入门 ]
大家好! 我做了一个后台,在 view 中有这两行来引入 css 和 Js
use frontend\assets\TestAsset;
TestAsset::register( $this );
由于YII默认是有layout (view/layout/main.php
), 那我就想禁用这个 layout,只使用我写的 css 和 js 就好了。
于是, 我在 controller 中写了 public $layout = false;
然后,layout 确实是没有了,但是我在 view 中 asset 引入的资源没有了。。
这是为什么呢? 感谢大家!
共 5 条回复
-
benbenhu007 回复于 2016-04-20 15:18 举报
$layout = false;
意思是不引用模板 就不能使用该模板引用的样式和js 代表该页面需要重新引用所有css和jsParamore 觉得很赞 -
-
-
-
这是我修改后的 views/layouts/main.php 文件 你参考下吧
<?php /* @var $this \yii\web\View */ /* @var $content string */ use yii\helpers\Html; use yii\bootstrap\Nav; use yii\bootstrap\NavBar; use yii\widgets\Breadcrumbs; use app\assets\AppAsset; ?> <?php $this->beginPage() ?> <!DOCTYPE html> <html lang="<?= Yii::$app->language ?>"> <head> <meta charset="<?= Yii::$app->charset ?>"> <meta name="viewport" content="width=device-width, initial-scale=1"> <?= Html::csrfMetaTags() ?> <title><?= Html::encode($this->title) ?></title> <?php $this->head() ?> </head> <body> <?php $this->beginBody() ?> <div class="wrap"> <?= $content ?> </div> </div> <?php $this->endBody() ?> </body> </html> <?php $this->endPage() ?>
yuwuy 觉得很赞
Paramore
注册时间:2016-03-29
最后登录:2016-05-28
在线时长:3小时25分
最后登录:2016-05-28
在线时长:3小时25分
- 粉丝1
- 金钱10
- 威望0
- 积分40