这可以通过以下方式实现
echo $this->partial('layout/header', array('vr' => 'zf2'));
您可以使用访问视图中的变量
echo $this->vr;
不要忘记在 module.config.php 文件的 view_manager 中添加以下行。
'layout/header' => __DIR__ . '/../view/layout/header.phtml',
添加后看起来像这样
return array(
'view_manager' => array(
'template_path_stack' => array(
'user' => __DIR__ . '/../view' ,
),
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'layout/header' => __DIR__ . '/../view/layout/header.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
),
);