Home > Article > PHP Framework > Yii implementation does not load the layout file
The Yii framework will render the layout by default when rendering the template. The newly created project also contains 3 default layouts: main.php
, column1 .php
, column2.php
, and a public controller Controller.php
(in the components directory) is created by default, and the default SiteController.php
is the inherited Controller.php. This controller specifies the layout file as column1.php
.
First let us look at the steps required to render a template:
1. Pass $this->render('index' in the controller )
to start rendering the index.php view file;
2. When rendering index, first parse the php script in index.php
, and then save the parsed result. Go to the $content
variable;
3. The system checks whether the layout file is specified. First look for the $this->layout
attribute of the controller. If this value is not If it is empty, then render()
renders the layout file and uses the $content
value as a variable in the layout file, that is, using 4994d9755a4641a236c719fc3585ac19
can output the parsed content in index.php, and this layout is designated as column1.php
by default in Controller
, in this In the layout, the project's default layout file main.php is nested.
4. If the controller does not specify the layout attribute, it will look for the layout attribute in the project configuration, which is the layout attribute in main.php
, and this attribute does not need to be manually specified. , the default is the views/layouts/main.php
file. Parse this layout file through render
, and pass the content of index.php into the $content variable.
That is to say, according to the default situation, we need to render three files to render a view, namely index.php
, column1.php
, main .php
.
For people who are not used to layout mode, this will undoubtedly increase the trouble.
Close method:
But turning off layout mode is very simple. You can set the layout
property in Controller
to false
is enough.
Examples are as follows:
SiteController extends Controller{ public $layout=false; //重写这个属性就可以了 //其他方法 }
Recommended related articles and tutorials: yii tutorial
The above is the detailed content of Yii implementation does not load the layout file. For more information, please follow other related articles on the PHP Chinese website!