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

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

WBOY
Release: 2016-06-06 20:35:25
Original
1147 people have browsed it

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

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

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

该怎么做呢?

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

解决方法:

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

回复内容:

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

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

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

该怎么做呢?

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

解决方法:

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

<code>$this->content->layout = '@app/views/layouts/other.php';
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template