Search code examples
zend-frameworkframeworkszend-framework2viewmodeladdchild

ZF2 ViewModel addChild(). How to read it on layout (not template)?


I have problem with Zend Framework 2 and ViewModel with which i can not deal.

I want to do really simple thing, but this framework is not helping with that... I have for example simple layout:

<html>
<div id="window">
<?php echo $this->window; 
// or whatever working....
?>
</div>
<div id="content">
<?php echo $this->content; ?>
</div>
</html>

I want to add content of window in a place, where $this->window is printed. I have tried by:

$view = new ViewModel();
$window = new ViewModel();
$window->setTemplate('window/window_error222'); // Template with error to include on layout
$view->addChild($window, 'window');

It works fine on content file, but i cannot access 'window' variable in layout file. Is there any solution for that? I dont want to create another template for window div.


Solution

  • I have resolved my problem by this:

    $layout = $this->layout();
    $layout->addChild($window, 'window');