我在Zend Framework 2中为段路由创建段子路由时遇到了一些麻烦。我试图从文档中获取它,但这对我来说有点混乱。想知道有人可以帮助我。
这基本上是我想要定义的路线:
root/monitor/customer/12424/job/1243
其中12424是客户ID,1243是作业ID。工作部分也可以是不同的行动。
以下是我尝试使用路由的内容。我尝试了几种不成功的方法,但这只是我目前的方法。一直到工作都有效。
'router' => array(
'routes' => array(
'monitor' => array(
'type' => 'segment',
'options' => array(
'route' => '/monitor[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Monitor\Controller\Monitor',
'action' => 'index',
),
),
'child_routes' => array(
'customer' => array(
'type' => 'segment',
'options' => array(
'route' => '/customer/:id[/][/:action/:jobid]',
'defaults' => array(
'action' => 'customer'
)
),
),
),
),
),
),
我收到以下404错误:
The requested URL could not be matched by routing.
答案 0 :(得分:0)
你应该尝试通过分离静态部分并将其余部分放在child_routes中来重构它:
'monitor' => array(
'type' => 'literal',
'options' => array(
'route' => '/monitor',
),
'child_routes' => array(
'something' => array(
'type' => 'segment',
'options' => array(
'route' => '[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Monitor\Controller\Monitor',
'action' => 'index',
),
),
),
'customer' => array(
'type' => 'segment',
'options' => array(
'route' => '/customer/:id[/:action/:jobid]',
'defaults' => array(
'action' => 'customer'
)
),
),
),
),