Zend框架2路由错误


Zend Framework 2 Routing Error

我试图在Zend 2中创建一个自定义用户模块,但我在"段"answers"文字"中路由有问题。

我已经谷歌了很多没有找到解决方案。我的模块是"User":

当我尝试访问URL siteurl/user/login or siteurl/user时,我得到一个错误。

 "The requested controller could not be mapped to an existing controller class."

我已经有一个用户控制器在"module' user 'src' user ' controller 'UserController"。

我已经在module.config.php中定义了路由。

return array(
    'controllers' => array(
        'invokables' => array(
            'User'Controller'User' => 'User'Controller'UserController',
        ),
    ),
    // The following section is new and should be added to your file
    'router' => array(
        'routes' => array(
            'user' => array(
                'type' => 'Literal',
                'priority' => 1000,
                'options' => array(
                    'route' => '/user',
                    'defaults' => array(
                        'controller' => 'user',
                        'action'     => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'login' => array(
                        'type' => 'Literal',
                        'options' => array(
                            'route' => '/user/login',
                            'defaults' => array(
                                'controller' => 'user',
                                'action'     => 'login',
                            ),
                        ),
                    ),
                    'authenticate' => array(
                        'type' => 'Literal',
                        'options' => array(
                            'route' => '/user/authenticate',
                            'defaults' => array(
                                'controller' => 'user',
                                'action'     => 'authenticate',
                            ),
                        ),
                    ),
                    'logout' => array(
                        'type' => 'Literal',
                        'options' => array(
                            'route' => '/user/logout',
                            'defaults' => array(
                                'controller' => 'user',
                                'action'     => 'logout',
                            ),
                        ),
                    ),
                    'register' => array(
                        'type' => 'Literal',
                        'options' => array(
                            'route' => '/user/register',
                            'defaults' => array(
                                'controller' => 'user',
                                'action'     => 'register',
                            ),
                        ),
                    ),
                    'changepassword' => array(
                        'type' => 'Literal',
                        'options' => array(
                            'route' => '/user/change-password',
                            'defaults' => array(
                                'controller' => 'user',
                                'action'     => 'changepassword',
                            ),
                        ),                        
                    ),
                    'changeemail' => array(
                        'type' => 'Literal',
                        'options' => array(
                            'route' => '/user/change-email',
                            'defaults' => array(
                                'controller' => 'user',
                                'action' => 'changeemail',
                            ),
                        ),                        
                    ),
                ),
            ),
        ),
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'album' => __DIR__ . '/../view',
        ),
    ),
);

我在这里错过了什么?

你的路由没有默认的'__NAMESPACE__'键定义,所以路由器不知道在哪里寻找一个名为user的控制器

// The following section is new and should be added to your file
'router' => array(
    'routes' => array(
        'user' => array(
            'type' => 'Literal',
            'priority' => 1000,
            'options' => array(
                'route' => '/user',
                'defaults' => array(
                    // add the namespace
                    '__NAMESPACE__' => 'User'Controller'
                    'controller' => 'user',
                    'action'     => 'index',
                ),
            ),
            // ..
        ),
    ),
),