2017-03-23 220 views
1

我是新來的Zend-Framework3。兒童路線不工作

並將我的ZF2應用程序遷移到ZF3。

在這個孩子的路線不工作。

這裏是路由器從我module.config.php

'router' => [ 
    'routes' => [ 
     'application' => [ 
      'type' => Segment::class, 
      'options' => [ 
       'route' => '/application', 
       'defaults' => [ 
        'controller' => Controller\IndexController::class, 
        'action' => 'index', 
       ], 
      ], 
      'may_terminate' => true, 
      'child_routes' => [ 
       'kk' => [ 
        'type' => Literal::class, 
        'options' => [ 
         'route' => 'kk', 
         'defaults' => [ 
          'controller' => Controller\IndexController::class, 
          'action' => 'kk' 
         ], 
        ], 
       ], 
      ] 
     ] 
    ], 
], 

當我打電話/application/kk行動。它生成404 error

我在哪裏錯了?還是我必須手動註冊所有操作?

回答

3

...我必須手動註冊所有操作嗎?

不,你只是缺少路線值

'router' => [ 
    'routes' => [ 
     'application' => [ 
      'type' => Segment::class, 
      'options' => [ 
       'route' => '/application', 
       'defaults' => [ 
        'controller' => Controller\IndexController::class, 
        'action' => 'index', 
       ], 
      ], 
      'may_terminate' => true, 
      'child_routes' => [ 
       'kk' => [ 
        'type' => Literal::class, 
        'options' => [ 
         'route' => '/kk', <-- here 
         'defaults' => [ 
          'controller' => Controller\IndexController::class, 
          'action' => 'kk' 
         ], 
        ], 
       ], 
      ] 
     ] 
    ], 
], 

/字符只要行動kk存在,你不應該得到404錯誤。

如果您的路線與動作名稱相同。您可以使用Segment類型:

'application' => [ 
     'type' => Segment::class, 
     'options' => [ 
      'route' => '/application[/:action]', 
      'constraints' => [ 
       'action' => '[a-zA-Z][a-zA-Z0-9_-]*' 
      ], 
      'defaults' => [ 
       'controller' => Controller\IndexController::class, 
       'action'  => 'index', 
      ], 
     ], 
    ]