Zend framework2 ZF2正在从控制器/索引/登录中删除索引
我正在尝试从url中删除索引操作。刚刚用auth模块启动了ZF2。 我的module.config.php如下所示 使用下面的代码,我可以看到登录屏幕,可以登录和注销,但当涉及到注册和密码重置选项时,url路由是domain/auth/index/registration,而不是domain/auth/registration 非常感谢您的帮助。 提前谢谢Zend framework2 ZF2正在从控制器/索引/登录中删除索引,zend-framework2,Zend Framework2,我正在尝试从url中删除索引操作。刚刚用auth模块启动了ZF2。 我的module.config.php如下所示 使用下面的代码,我可以看到登录屏幕,可以登录和注销,但当涉及到注册和密码重置选项时,url路由是domain/auth/index/registration,而不是domain/auth/registration 非常感谢您的帮助。 提前谢谢 return array( 'controllers' => array( 'invokables' => array
return array(
'controllers' => array(
'invokables' => array(
'Auth\Controller\Index' => 'Auth\Controller\IndexController',
'Auth\Controller\Registration' => 'Auth\Controller\RegistrationController',
'Auth\Controller\Admin' => 'Auth\Controller\AdminController',
) ,
) ,
'router' => array(
'routes' => array(
'auth' => array(
'type' => 'Segment',
'options' => array(
'route' => '/auth[/:action]',
'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',
// ),
'template_path_stack' => array(
'auth' => __DIR__ . '/../view'
) ,
'display_exceptions' => true,
) ,
'service_manager' => array(
// added for Authentication and Authorization. Without this each time we have to create a new instance.
// This code should be moved to a module to allow Doctrine to overwrite it
'aliases' => array( // !!! aliases not alias
'Zend\Authentication\AuthenticationService' => 'my_auth_service',
) ,
'invokables' => array(
'my_auth_service' => 'Zend\Authentication\AuthenticationService',
) ,
) ,
) 您可以尝试对此路由使用文本而不是段类型来从url中删除索引:
'auth' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/auth/registration[:/]',
'defaults' => array(
'__NAMESPACE__' => 'Auth\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
),
来自zf2文档:文本路由用于执行URI路径的精确匹配。因此,配置仅仅是您想要匹配的路径,以及您想要在匹配中返回的“默认值”或参数。