Zend Framework 2 の子ビュー モデルを試していますが、何らかの理由で子ビューがレンダリングされません。$this->content はコンテンツなしで終了します。
私のスクリプト
use Zend\View\Renderer\PhpRenderer;
use Zend\View\Resolver;
use Zend\View\Model\ViewModel;
$renderer = new PhpRenderer();
$resolver = new Resolver\AggregateResolver();
$renderer->setResolver($resolver);
$map = new Resolver\TemplateMapResolver(array(
'layout' => APP_PATH . '/views/layouts/test-layout.phtml',
'test1' => APP_PATH . '/views/scripts/test1.phtml',
'test2' => APP_PATH . '/views/scripts/test2.phtml',
));
$stack = new Resolver\TemplatePathStack(array(
'script_paths' => array(
APP_PATH . '/views/scripts',
)
));
$resolver->attach($map) // this will be consulted first
->attach($stack);
$layout = new ViewModel();
$layout->setTemplate('layout');
$model = new ViewModel(array(
'name' => '<h1>World</h1>',
'date' => date('Y-m-d'),
));
$model->setTemplate('test1');
$layout->addChild($model, 'content');
echo $renderer->render($layout);
私の「レイアウト」ファイル
<!DOCTYPE html>
<html lang="en">
<head>
<title>Testing layouts and nested view models</title>
</head>
<body>
<div class='container'>
<?php echo $this->content; ?>
</div>
</body>
</html>
私の「test1」ビュー
<p>Hello <?php echo $this->escapeHtml($this->name); ?>, its <?php echo $this->date; ?></p>
出力
<!DOCTYPE html>
<html lang="en">
<head>
<title>Testing layouts and nested view models</title>
</head>
<body>
<div class='container'>
</div>
</body>
</html>
期待される出力
<!DOCTYPE html>
<html lang="en">
<head>
<title>Testing layouts and nested view models</title>
</head>
<body>
<div class='container'><p>Hello <h1>World</h1>, its 2013-10-10</p>
</div>
</body>
</html>