2013-08-30 18 views
0

我在Zend Framework 2中爲段路由製作段子路由時遇到了一些麻煩。我試圖從文檔中獲取它,但對我來說有點困惑。想知道任何人都可以幫助我。TreeRouteStack ZF2中的段

這基本上是我要定義的航線:

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

因爲它是'route'=>'/ customer /:id [/] [/:action /:jobid]',所以使用它的任何特殊原因,從外表看起來它就像你正在基於id –

回答

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' 
         ) 
        ), 
       ), 
      ), 
     ),