這樣的路由我實際上有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'
)
)
),
但它沒有得到變量「控制器」和「行動」。
有沒有人有如何解決這個問題的建議?