如何将变量传递给布局? [英] How to pass variables to layout?
本文介绍了如何将变量传递给布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何将变量从控制器传递到视图中
I know how to pass variable from controller into a view:
$this->render('view_name', array('variable_name'=>'variable_value'));
但是我想将一些变量传递给布局.控制器和布局之间的唯一连接似乎是控制器类中的public $ layout属性,如下所示:
however I'd like to pass some variables to layout. The only connection between controller and layout seems to be the public $layout attribute in controller class, like this:
public $layout='//layouts/column2';
但是,我看不到将变量传递给它的方法吗?
However, I do not see a way to pass a variable to it?
推荐答案
在您的控制器中,您可以执行以下操作:
From your controller you can do something like this:
$this->render('/mail/registration',array('url'=>$url, 'description'=>'some description'));
,然后从您的视图访问变量,如下所示:
and access the variables from your view like this:
<h3><?php echo $url; ?></h3>
这是您的答案;您可以像这样从布局访问这些相同的变量:
and here is your answer; you can access these same variables from the layout like this:
<h3><?php echo $data['url']; ?></h3>
这篇关于如何将变量传递给布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文