我正在尝试在 ZF2 中创建一个简单的电子邮件模板测试,我正在使用依赖注入来创建 PhpRenderer 类的实例,并设置了所有依赖项。
由于 AggregateResolver 中不存在路径“电子邮件”,看来我可能正在努力链接注入。
在 module.config.php 里面
'di' => array(
'instance' => array(
'Zend\View\Resolver\TemplatePathStack' => array(
'options' => array(
'script_paths' => array(
'email' => __DIR__ . '/../view/application/email',
),
),
),
'Zend\View\Resolver\AggregateResolver' => array(
'attach' => array(
'Zend\View\Resolver\TemplatePathStack',
),
),
'Zend\View\Renderer\PhpRenderer' => array(
'setResolver' => 'Zend\View\Resolver\AggregateResolver',
),
),
),
在 TestController.php 里面
$di = new \Zend\Di\Di;
$renderer = $di->get('Zend\View\Renderer\PhpRenderer');
$content = $renderer->render('email/test', null);
echo($content);
信息:
Zend\View\Renderer\PhpRenderer::render: Unable to render template "email/test"; resolver could not resolve to a file
任何帮助将不胜感激。
由于编写了上述内容,我一直在玩耍并从 di 数组中删除了 TemplatePathStack,这根本没有任何效果,所以我不确定 AggregateResolver 是否正在使用它,所以它可能是一个链接问题:
'di' => array(
'instance' => array(
/*'Zend\View\Resolver\TemplatePathStack' => array(
'addPaths' => array(
'paths' => array(
'email' => __DIR__ . '/../view/application/email',
),
),
),*/
'Zend\View\Resolver\AggregateResolver' => array(
'attach' => array(
'Zend\View\Resolver\TemplatePathStack',
),
),
'Zend\View\Renderer\PhpRenderer' => array(
'setResolver' => 'Zend\View\Resolver\AggregateResolver',
),
),
),
阿博格罗夫