问题
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