访问控制器动作变量到 zf2 布局 [英] access controller action variables to zf2 layout
本文介绍了访问控制器动作变量到 zf2 布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了两种布局:一种用于登录页面,另一种用于网站的其余部分.登录后,我想将变量从登录控制器传递到 zf2 布局,但无法访问.
I have created two layouts: one for the login page and another for the rest of the site. After login I want to pass variables from login controller to zf2 layout, but not able to access.
如何访问在控制器操作中创建的布局中的变量?
How can i access the variables in layout created in a controller action?
推荐答案
在控制器中实现此目的的一些方法:
Some ways to do that in your controller:
$viewmodel = new ViewModel();
$viewmodel->setVariable('myvar', $myvar);
return $viewmodel;
使用 layout()
$this->layout()->myvar = $myvar;
进入你的视图脚本
<?php echo $this->myvar; ?>
这篇关于访问控制器动作变量到 zf2 布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文