这样的路由我实际上有2个模块(应用程序和管理员)在我的ZF2应用程序中,我想要一个类似于ZF1的URL路由。目前,我有以下途径:ZF2 - 试图创建一个像ZF1
'router' => array
(
'routes' => array
(
'admin' => array
(
'type' => 'Segment',
'options' => array
(
'route' => 'admin/[:controller[/:action]]',
'constraints' => array
(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array
(
'__NAMESPACE__' => 'Admin\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array
(
'wildcard' => array
(
'type' => 'Wildcard'
)
)
),
),
),
所以它将匹配 “/ admin” 的, “/管理/控制”, “/管理/控制/动作”,而不是 “/控制器/动作”。
现在我需要一个路由到应用程序模块。问题是,如果我只是使用类似路由的模块应用程序,这条新路线将匹配“/ admin/controller”作为controller =“admin”和action =“controller”。
我也试过在应用以下的正则表达式路线:
'application' => array
(
'type' => 'Regex',
'options' => array
(
'regex' => '/(?<controller>^(?!(admin)$)[a-zA-Z][a-zA-Z0-9_-]*)?' .
'(/[a-zA-Z][a-zA-Z0-9_-]*)?',
'spec' => '/%controller%/%action%',
/*'constraints' => array
(
//The controller cannot be "admin"
'controller' => '^(?!(admin)$)[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),*/
'defaults' => array
(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array
(
'wildcard' => array
(
'type' => 'Wildcard'
)
)
),
但它没有得到变量“控制器”和“行动”。
有没有人有如何解决这个问题的建议?