是否可以在Zend Framework 2中将数组中的多个视图添加到父视图中? 例如:ZF2作为数组嵌套视图
childView.php
echo $this->data;
parentView.php:
foreach($this->views as $view)
echo '<div>'.$view.'</div>';
Controller.php这样:
public function actionIndex(){
$children = array(1,2,3);
foreach($children as $child){
$childView = new ViewModel(array('data' => $child));
$childView->setTemplate('childView');
$childrenViews[] = $childView;
}
$view = new ViewModel();
$view->setTemplate('parentView');
// some function that adds the childrenViews to the parentView;
return $view;
}
预期输出:<div>1</div><div>2</div><div>3</div>
ps:这是虚拟代码,所以请忽略可能的语法错误。
也许看看Akrabats'Zf2TestApp' - > http://zf2test.akrabat.com/,特别是多视图模型 - > http://zf2test.akrabat.com/view/multipleViewModels。您可以在github上找到源代码(它与测试应用程序链接) – Crisp 2013-05-14 10:26:38