Zend Framework 2 如何在模块内渲染部分? [英] How does Zend Framework 2 render partials inside a module?
问题描述
我的模块内的目录结构是这样的:
I've got something like this for my directory structure inside a module:
Api
├── Module.php
├── config
│ └── module.config.php
├── src
│ └── ( ..etc ..)
└── view
├── api
│ └── api
│ └── index.phtml
└── partial
└── test.phtml
然后,我这样做:
<?= $this->partial('partial/test.pthml', array()); ?>
但是,我得到:
05-Jun-2012 14:56:58] PHP 致命错误:未捕获的异常带有消息的Zend\View\Exception\RuntimeException"'Zend\View\Renderer\PhpRenderer::render: 无法渲染模板部分/test.pthml";解析器无法解析到文件中/Users/jeff/web/n/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:463
05-Jun-2012 14:56:58] PHP Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template "partial/test.pthml"; resolver could not resolve to a file' in /Users/jeff/web/n/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:463
我的部分应该去哪里?
推荐答案
这可以通过
echo $this->partial('layout/header', array('vr' => 'zf2'));
您可以使用
echo $this->vr;
不要忘记在 module.config.php 文件的 view_manager 中添加以下行.
don't forget to add following line in your view_manager of module.config.php file.
'layout/header' => __DIR__ . '/../view/layout/header.phtml',
添加后是这样的
return array(
'view_manager' => array(
'template_path_stack' => array(
'user' => __DIR__ . '/../view' ,
),
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'layout/header' => __DIR__ . '/../view/layout/header.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
),
);
这篇关于Zend Framework 2 如何在模块内渲染部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!