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

How to set layouts in yii

(*-*)浩
(*-*)浩Original
2019-11-05 11:25:321830browse

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

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;;}

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}

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!

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