ZF2 nested views as array -


is possible add multiple views in array parent view in zend framework 2? example:

childview.php

echo $this->data; 

parentview.php:

foreach($this->views $view)     echo '<div>'.$view.'</div>'; 

controller.php:

public function actionindex(){     $children = array(1,2,3);     foreach($children $child){         $childview = new viewmodel(array('data' => $child));         $childview->settemplate('childview');         $childrenviews[] = $childview;     }     $view = new viewmodel();     $view->settemplate('parentview');      // function adds childrenviews parentview;      return $view; } 

expected output: <div>1</div><div>2</div><div>3</div>

ps: it's dummy code please ignore possible syntax errors.

you following:

public function actionindex(){     $children = array(1,2,3);     foreach($children $child){         $childview = new viewmodel(array('data' => $child));         $childview->settemplate('childview');         $view->addchild($childview, 'the-child-views', true);     }     $view = new viewmodel();     $view->settemplate('parentview');      return $view; } 

this line:

$view->addchild($childview, 'the-child-views', true); 

will append child views 1 var. can echo views using:

<?php echo $this->the-child-views ?> 

hope it's looking for.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -