yii怎么设置layouts

yii怎么设置layouts,第1张

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->layout = 'loginlayout';}

通过控制器的init()方法去定义该变量public function init(){

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

以上就是yii怎么设置layouts的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/701562.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-23
下一篇 2022-04-23

发表评论

登录后才能评论

评论列表(0条)

保存