Reputation: 115
How can I pass parameters to a view helper in layout view from a controller, or pass parameters to view helper somehow else in Zend Framework 3?
Upvotes: 0
Views: 498
Reputation: 1246
To pass parameters from a controller to a view helper in the layout view, you want to pass the parameter from the controller to the layout, and then call the view helper in the layout using the parameter it got from the controller.
// in the controller
$this->layout()->myParameter = 'foo';
then
// in the layout view
// set a parameter value for cases where a controller doesn't pass a parameter
$myParameterValue = ( isset($this->myParameter)) ? $this->myParameter : null );
echo $this->myViewHelper($myParameterValue);
Upvotes: 1