2014-01-23 29 views
0

什麼我嘗試實現:沒有工作ZF2段的孩子航線

domain.com/user     = UserController::index 
domain.com/user/profile   = UserController::profile 
domain.com/user/profile/9   = UserController::profile (with query param id=9) 
domain.com/user/profile/9/edit  = UserController::editProfile (with query param id=9) 

所以我有以下途徑:

'user' => array(
    'type' => 'Segment', 
    'options' => array(
     'route' => '/user', 
     'defaults' => array(
      '__NAMESPACE__' => 'YrmUser\Controller', 
      'controller' => 'User', 
      'action'  => 'index', 
     ), 
    ), 
    'may_terminate' => true, 
    'child_routes' => array(
     'profile' => array(
      'type' => 'Segment', 
      'options' => array(
       'route' => '/profile[/:id]', 
       'defaults' => array(
        'action' => 'profile', 
       ), 
       'constraints' => array(
        'id' => '[0-9]*' 
       ), 
      ), 
      'may_terminate' => true, 
      'child_routes' => array(
       'edit' => array(
        'type' => 'Segment', 
        'options' => array(
         'route' => '/edit', 
         'defaults' => array(
          'action' => 'editProfile', 
         ), 
        ), 
        'may_terminate' => true 
       ), 
      ) 
     ), 
    ) 
) 

它還挺作品,除了一個事實,即從不查詢參數ID獲得價值。 任何人誰可以告訴我,我在做什麼錯,即時猜測它太簡單的東西...

由於提前,

YRM

回答

1

爲我工作。

我在行動var_dumped的$this->params ('id')和得到這個:

/user 
null 

/user/profile 
null 

/user/profile/99 
string '99' (length=2) 

/user/profile/99/edit 
string '99' (length=2) 
+0

它確實是一個非常愚蠢的錯誤..我用fromQuery應該使用fromRoute – YRM