简体   繁体   中英

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

如何从控制器将参数传递给布局视图中的视图助手,或者如何在Zend Framework 3中以其他方式传递参数以查看助手?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM