美文网首页
YII2 引用视图布局

YII2 引用视图布局

作者: Mr_敬zZ | 来源:发表于2017-08-04 15:07 被阅读0次

方案1:控制器内成员变量
public $layout = false; //不使用布局
public $layout = "main"; //设置使用的布局文件

方案2:控制器成员方法内
$this->layout = false; //不使用布局
$this->layout = "main"; //设置使用的布局文件

方案3:视图中选择布局
$this->context->layout = false; //不使用布局
$this->context->layout = 'main'; //设置使用的布局文件

layouts 部分覆盖:
主模版
<?php if (isset($this->blocks['block_foot'])): ?>
<?= $this->blocks['block_foot'] ?>
<?php else: ?>
<?php $this->beginContent('@app/views/layouts/footer.php'); ?>
<?php $this->endContent(); ?>
<?php endif; ?>

修改模版
<?php $this->beginBlock('block_foot'); ?>
<?php $this->beginContent('@app/views/layouts/footer2.php'); ?>
<?php $this->endContent(); ?>
<?php $this->endBlock(); ?>

相关文章

网友评论

      本文标题:YII2 引用视图布局

      本文链接:https://www.haomeiwen.com/subject/awnvlxtx.html