php - Zend Framework 2 如何在模块内呈现部分?

标签 php zend-framework2

我在模块中的目录结构有这样的东西:

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 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'));

您可以使用

访问 View 中的变量
echo $this->vr;

不要忘记在 module.config.php 文件的 view_manager 中添加以下行。

'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',
        ),


    ),    

);

关于php - Zend Framework 2 如何在模块内呈现部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10903451/

相关文章:

php - 学习 PHP、 boolean 代数

php - 单击按钮时方法发布不起作用

php - Zend\Session\Container Session 验证失败异常 -- Object(Closure) ZF2

forms - $form->isValid 说它无效,但我的表单没有显示任何错误消息 - Zend Framework 2

php - 为特定文件夹/路由禁用 Laravel 路由

php - 将数据中创建的 Magento 客户帐户更改为网站

php - 我发送 cURL 帖子的页面必须对 "Respond"做什么?

php - Zend2 Form - 将属性设置为选择元素中的选项

zend-framework - 面向 Zend 框架新手的 Zend Framework 2

php - 克隆不能处理 zf2 Doctrine MongoOSEModule 中的嵌入式文档