Home > Article > PHP Framework > How to set layouts in yii
Usage of yii's layouts
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 = 'loginlayout';}
Define the variable through the init() method of the controller public function init(){
$this->layout = 'loginlayout'; 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!