Home >Backend Development >PHP Tutorial >yii2 - 由views/page/xxx.php 来决定使用哪个layout

yii2 - 由views/page/xxx.php 来决定使用哪个layout

WBOY
WBOYOriginal
2016-06-06 20:35:251149browse

想法如下:
有时候我觉得用views中的参数来决定用哪个layout
这样子该怎么做呢?

frontend/views/page/xxx.php
$this->layout='main'; 报错

<?php include("../layouts/main.php"); ?>报错

该怎么做呢?

由view倒置决定使用哪个layout怎么做到?

解决方法:

<code>$this->context->layout='page';
</code>

回复内容:

想法如下:
有时候我觉得用views中的参数来决定用哪个layout
这样子该怎么做呢?

frontend/views/page/xxx.php
$this->layout='main'; 报错

<?php include("../layouts/main.php"); ?>报错

该怎么做呢?

由view倒置决定使用哪个layout怎么做到?

解决方法:

<code>$this->context->layout='page';
</code>

<code>$this->content->layout = '@app/views/layouts/other.php';
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn