是否可以将数组中的多个视图添加到 Zend Framework 2 中的父视图?例如:
子视图.php
echo $this->data;
父视图.php:
foreach($this->views as $view)
echo '<div>'.$view.'</div>';
控制器.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:这是虚拟代码,所以请忽略可能的语法错误。