2017-03-23 168 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', 
      ], 
     ], 
    ]