ThinkPHP 5:使用模板布局

@20171106 - Day 9

1、ThinkPHP 5 模板布局:通过配置文件实现模板布局

1.1 开启配置文件
(1) common/config.php - 公共模块下面的配置文件;
(另外一种情况:直接就是配置 )
(2) 模块/config.php - 具体某个模块下的配置文件;

配置选项:

    'layout_on' => false, 是否开启模板布局
    'layout_name' => 'layout', 布局名称

1.2 要实现模板布局(什么情况下,应该使用模板布局)

(1) 建立一个布局 layout.html 文件,放到 view 目录

layout.html 文件内容如下:

{include file="public/header"}

{__CONTECNT__}

{include file="public/footer"}

(2) 建立你的 header.html, footer.html,放入自己的内容

(3) 建立一个控制器,调用视图输出,查看效果

Admin.php 

<?php
    namespace app\admin\controller;

    use \think\Controller;

    class Admin extends Controller {

        public function index()
        {
            return $this->fetch();
        }
    }

ThinkPHP 5 通过配置实现模板布局,有 bug。初次,通过应用配置文件进行设置 'layout_on' => true, 'layout_name' => 'layout' 时,ThinkPHP 5 引用的【应用部署目录/public】中的 header.html 与 footer.html 文件。
必须要将 layout.html 放到对应模块中
对具体模块添加具体的 config.php 文件,开启模板布局设置。再将其关闭,开启应用配置模板布局。结果就会默认引用模块视图中的 public/header.html, public/footer.html 文件。

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

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,973评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,466评论 25 708
  • 转载自cr180大神DiscuzX2.5完整目录结构【source程序文件库】 /source/admincp后台...
    cndaqiang阅读 889评论 1 2
  • 写在开头 先说说为什么要写这篇文章, 最初的原因是组里的小朋友们看了webpack文档后, 表情都是这样的: (摘...
    Lefter阅读 5,324评论 4 31
  • The vast majority have seen the famous tv programme “Jour...
    水写苍茫阅读 248评论 0 0