Home > PHP Framework > YII > How to set layouts in yii

How to set layouts in yii

(*-*)浩
Release: 2019-11-05 11:25:32
Original
1874 people have browsed it

Usage of yii's layouts

How to set layouts in yii

When we use render() in the controller, yii will load the layout by default . (Recommended learning: yii tutorial)

1.Modify the $layout variable in Controller.php under protected/componets to specify a custom layout file.

Example: $layout='//layouts/mylayout';

2. Create the mylayout.php layout file under protected/views/layouts.

3. Add your own code to the layout file, for example:

xxxx header 公共头部样式 xxxx
<?php echo $content; ?>
xxxx footer 公共尾部样式 xxxx
Copy after login

4. You will see your layout in the controller $this->render(); The style is rendered.

If you want to change the layout in the action, then write the variable in it public function actionIndex(){

   $this->layout = &#39;loginlayout&#39;;}
Copy after login

Define the variable through the init() method of the controller public function init(){

   $this->layout = &#39;loginlayout&#39;;
    parent::init(); // TODO: Change the autogenerated stub}
Copy after login

The above is the detailed content of How to set layouts in yii. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
yii
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