Yii2.0视频第十三讲——深入理解View——布局篇(Layout )

2015-10-22 0 946
Yii2.0视频第十三讲——深入理解View——布局篇(Layout )
布局变量哪里有

  • Controller里面定义了布局变量($layout)
  • Module里面定义了布局变量($layout)
    其中的web\application里面定义了$layout=’main’,所以在没有设置layout的时候 会使用默认的main.php布局文件

layout变量值
$this->layout=false;// null or ’@app/views/layouts/main.php’ or ’/main’ or ’main’

  • false,不使用布局文件
  • null,使用Module中定义的布局文件
  • 字符串,指定布局文件
            a、别名开头,指定布局文件路径
            b、/开头,指定app下面的布局文件
                    $this->layout=’/main’ //’/test-main’
            c、使用当前Module里面的布局文件

layout查找规则

  • 先查看当前Controller里面有没有定义布局变量
  • 如果为Null,查找所在Module里面定义的布局变量(包括父级Module)
  • 如果为false,则不使用布局文件
  • 如果为字符串,则直接使用

布局的嵌套

在布局文件里面使用beginContent

//指定view 文件(别名或者路径)
<?php $this->beginContent('@app/views/layouts/main.php'); ?>
<?php echo $content;?>
<?php $this->endContent(); ?>

布局高级使用
让布局文件支持多个变量

https://github.com/yiifans/luluc … ts/InhritLayout.php

在线播放

下载地址

遇见资源网 Yii2.0归档 Yii2.0视频第十三讲——深入理解View——布局篇(Layout ) http://www.ox520.com/12779.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务