access controller action variables to zf2 layout

左心房为你撑大大i 提交于 2019-12-31 03:57:09

问题


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?


回答1:


Some ways to do that in your controller:

Using view model

$viewmodel = new ViewModel();
$viewmodel->setVariable('myvar', $myvar);
return $viewmodel;

Using layout()

$this->layout()->myvar = $myvar;

Into your view script

<?php echo $this->myvar; ?>


来源:https://stackoverflow.com/questions/16665010/access-controller-action-variables-to-zf2-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!