加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Yii2如何将布局文件拆分为单独的页眉和页脚?

发布时间:2020-12-13 16:02:05 所属栏目:PHP教程 来源:网络整理
导读:我是新来的YII2,所以这可以是非常基本的问题. 我已经设置了初始申请.我有我的YII2应用程序/主题/标准的设置主题 现在,有一个默认的布局文件themes / standard / layouts / main.php – 这有标题和页脚的html代码 我想将标题分成主题/标准/布局/ header.php和
我是新来的YII2,所以这可以是非常基本的问题.

我已经设置了初始申请.我有我的YII2应用程序/主题/标准的设置主题

现在,有一个默认的布局文件themes / standard / layouts / main.php – 这有标题和页脚的html代码

我想将标题分成主题/标准/布局/ header.php和页脚到另一个文件

我在main.php中尝试过如下代码

<?php $this->render("header"); ?>

也试过了这个

<?php $this->render("//layouts/header"); ?>

但它没有呈现内容.
我不想绝对的路径,因为我有主题
你能帮助这个人吗

为了拥有嵌套布局,您可以使用下面的beginContent()和endContent()(例如在您的main.php布局中):
<?php $this->beginContent('@app/views/layouts/header.php'); ?>
    <!-- You may need to put some content here -->
<?php $this->endContent(); ?>

在头和尾之间的一切都将被替换为header.php中的$content.

截至Yii2的官方范例:

Sometimes you may want to nest one layout in another. For example,in different sections of a Web site,you want to use different layouts,while all these layouts share the same basic layout that generates the overall HTML5 page structure. You can achieve this goal by calling beginContent() and endContent() in the child layouts like the following:

<?php $this->beginContent('@app/views/layouts/base.php'); ?>

...child layout content here...

<?php $this->endContent(); ?>

As shown above,the child layout content should be enclosed within beginContent() and endContent(). The parameter passed to beginContent() specifies what is the parent layout. It can be either a layout file or alias.
Using the above approach,you can nest layouts in more than one levels.

http://www.yiiframework.com/doc-2.0/guide-structure-views.html#nested-layouts

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读