yii怎么設置layouts

YII的layouts的使用

yii怎么設置layouts

我們在控制器中使用render()時,yii會默認的載入布局。? ? ? (推薦學習:yii教程

1.protected/componets下的Controller.php中修改$layout變量,來指定自定義布局文件。

例:?$layout=’//layouts/mylayout’;

2.在protected/views/layouts下創建mylayout.php布局文件。

3.在布局文件中加入你自已的代碼,例:

xxxx?header?公共頭部樣式?xxxx <?php  echo $content; ?> xxxx?footer?公共尾部樣式?xxxx

4.在控制器$this->render();時你就會看到你的布局樣式被渲染出來了。

如果是想在action里改變布局,那么就把變量寫在里面public function actionIndex(){

???$this-&gt;layout?=?'loginlayout';}

通過控制器的init()方法去定義該變量public function init(){

???$this-&gt;layout?=?'loginlayout'; ????parent::init();?//?TODO:?Change?the?autogenerated?stub}

? 版權聲明
THE END
喜歡就支持一下吧
點贊7 分享