我将 ZF2 的 View 组件用作我的项目的独立组件,如下所示:
$renderer = new PhpRenderer;
$resolver = new Resolver\AggregateResolver();
$stack = new Resolver\TemplatePathStack(array(
'script_paths' => array(
__DIR__ . '/view'
)
));
$resolver->attach($stack);
$renderer->setResolver($resolver);
$model1 = new ViewModel;
$model1->setTemplate('template1');
$model1->setVariable('key', 'value');
$model2 = new ViewModel;
$model2->setTemplate('template2');
$model1->addChild($model2, 'child');
echo $renderer->render($model1);
它就像魅力一样。孩子在 model1 中渲染。但问题是,我如何访问key
model2 中的model1 变量?