在zend 2中指定正确路径的问题

时间:2014-04-25 21:07:11

标签: php configuration zend-framework2

我正在使用zend 2,我在 Auth 模块的module.config.php中有以下内容:

<?php
return array(
    'controllers' => array(
        'invokables' => array(
            'Auth\Controller\Index' => 'Auth\Controller\IndexController',   
            'Auth\Controller\Registration' => 'Auth\Controller\RegistrationController',
            'Auth\Controller\Themes' => 'Auth\Controller\ThemesController',
            'Auth\Controller\Admin' => 'Auth\Controller\AdminController',   
        ),
    ),
   'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Literal',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        'controller' => 'Auth\Controller\Index',
                        'action'     => 'index',
                    ),
                ),
            ),
            'auth' => array(
                'type'    => 'Segment',
                'options' => array(
                    'route'    => '/auth',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Auth\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action[/:id]]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'id'         => '[a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    'view_manager' => array(
         'template_map' => array(
             'layout/Auth'                  => __DIR__ . '/../view/layout/Auth.phtml',
             'application/layout/ajax-layout'   => __DIR__ . '/../view/layout/ajax-layout.phtml',
              'application/layout/normal-layout'   => __DIR__ . '/../view/layout/normal-layout.phtml',
             'auth/index/login'             => __DIR__ . '/../view/Auth/index/login.phtml',
             'auth/index/login-post'        => __DIR__ . '/../view/Auth/index/login-post.phtml',
             'auth/registration/registration-success' => __DIR__ . '/../view/Auth/registration/registration-success.phtml',
             'auth/registration/registration-failure' => __DIR__ . '/../view/Auth/registration/registration-failure.phtml',
             'auth/themes/creation-failure' => __DIR__ . '/../view/Auth/themes/creationFailure.phtml', 
             'auth/themes/create' => __DIR__ . '/../view/Auth/themes/createThemes.phtml',                
         ),
        'template_path_stack' => array(
            'auth' => __DIR__ . '/../view/'
        ),

        'display_exceptions' => true,
    ),
    'service_manager' => array(
        'aliases' => array(
            'Zend\Authentication\AuthenticationService' => 'my_auth_service',
        ),
        'invokables' => array(
            'my_auth_service' => 'Zend\Authentication\AuthenticationService',
        ),
    ),
);

当我在导航仪中输入头文件夹名称:test/我得到一个空白页面,其中只包含这四个单词:

Auth Controller Index Action

而不是真实的页面。

这是什么?谁可以帮忙?

1 个答案:

答案 0 :(得分:0)

我通过以下方式解决了这个问题:

'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Literal',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        'controller' => 'Auth\Controller\Index',
                        'action'     => 'login',
                    ),
                ),
            ),

因此它将走自然之路:

Router -> Routes -> Home  

并且路线只找到斜线:

'route' => '/'

默认为:

'defaults' => array(
   'controller' => 'Auth\Controller\Index',
   'action'     => 'login',
),