Alaksander
Alaksander

Reputation: 115

Zend Framework 3 Pass Parameters from Controller to View Helper in Layout View

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

Answers (1)

jcropp
jcropp

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

Related Questions