Zend Framework 2:无法渲染模板 - 扭曲

时间:2014-02-14 14:13:56

标签: php zend-framework2

我知道有很多问题和回答“无法渲染模板”,但我的问题有一个转折。

当我打开此网址时:http://localhost:8080/users/usermanager/index

我收到此错误:Zend\View\Renderer\PhpRenderer::render: Unable to render template "users/user-manager/index"; resolver could not resolve to a file

我已将user-manager重命名为usermanager,这完全没问题。我已经使用了整个代码,找不到对user-manager的任何引用。为什么Zend还在寻找它?

我的module.config.php:

<?php

namespace Users;

return array (
        'controllers' => array (
                'invokables' => array (
                        'Users\Controller\Index' => 'Users\Controller\IndexController',
                        'Users\Controller\Register' => 'Users\Controller\RegisterController',
                        'Users\Controller\Login' => 'Users\Controller\LoginController',
                        'Users\Controller\UserManager' => 'Users\Controller\UserManagerController' 
                ) 
        ),

        'router' => array (
                'routes' => array (
                        'users' => array (
                                'type' => 'Literal',
                                'options' => array (
                                        'route' => '/users',
                                        'defaults' => array (
                                                '__NAMESPACE__' => 'Users\Controller',
                                                'controller' => 'Index',
                                                'action' => 'index' 
                                        ) 
                                ),
                                'may_terminate' => true,
                                'child_routes' => array (
                                        'default' => array (
                                                'type' => 'Segment',
                                                'options' => array (
                                                        'route' => '/[:controller[/:action]]',
                                                        'constraints' => array (
                                                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*' 
                                                        ),
                                                        'defaults' => array () 
                                                ) 
                                        ) 
                                ) 
                        ),
                        'usermanager' => array (
                                'type' => 'Segment',
                                'options' => array (
                                        'route' => '/usermanager[/:action[/:id]]',
                                        'constraints' => array (
                                                'action' => '[a-zA-z][a-zA-z0-0_-]*',
                                                'id' => '[a-zA-Z0-9_-]*' 
                                        ),
                                        'defaults' => array (
                                                'controller' => 'Users\Controller\UserManager',
                                                'action' => 'index' 
                                        ) 
                                ) 
                        ) 
                ) 
        ),
        'service_manager' => array (
                'abstract_factories' => array (
                        'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
                        'Zend\Log\LoggerAbstractServiceFactory' 
                ),
                'aliases' => array (
                        'translator' => 'MvcTranslator' 
                ) 
        ),
        'translator' => array (
                'translation_file_patterns' => array (
                        array (
                                'type' => 'gettext',
                                'base_dir' => __DIR__ . '/../language',
                                'pattern' => '%s.mo',
                                'text_domain' => __NAMESPACE__ 
                        ) 
                ) 
        ),
        'view_manager' => array (
                'template_path_stack' => array (
                        'users' => __DIR__ . '/../view' 
                ) 
        ) 
);

感谢您的帮助!

2 个答案:

答案 0 :(得分:5)

我认为您还必须将UserManager更改为Usermanager

在搜索默认视图时,Zend2会自动将StrningsLikeThis翻译为strings-like-this

答案 1 :(得分:2)

如果您真的想要使用命名约定之外的模板名称,可以像这样创建一个template_map:

  

module.config.php

view_manager' => array(
   ...   
   'template_map' => array(
      'users/user-manager/index'  => __DIR__ . '/../view/users/user-manager/index.phtml',
   ...

我个人只是坚持惯例,因为创建这些地图有点麻烦。