YII2 引用视图布局

方案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(); ?>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 回首页 第一部分 Drupal简介 Drupal overview A tour of Drupal fundam...
    王乂阅读 6,256评论 0 9
  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa阅读 12,866评论 0 6
  • 原文地址:http://www.android100.org/html/201606/06/241682.html...
    AFinalStone阅读 4,626评论 0 1
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,314评论 19 139
  • 谁见月色伴孤影 一身袈裟一世情 佛言万象终是苦 禅坛经筒照青灯 你若梵音落定 不染阡尘 我便落发为度 空门之内 六...
    深悟浅唱阅读 1,566评论 0 3