2017-03-23 6 views
1

Zend-Framework3を初めて使用しています。子ルートが動作していません

ZF2アプリケーションをZF3に移行します。

この子ルートでは、ルートは機能しません。私は/application/kkアクションを呼び出ししようとするとここで

は私の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' 
         ], 
        ], 
       ], 
      ] 
     ] 
    ], 
], 

からルータです。 404 errorを生成します。

どこが間違っていますか?または、すべてのアクションを手動で登録する必要がありますか?

答えて

3

...すべての操作を手動で登録する必要がありますか?

いいえ、あなただけの限りアクションkkが存在するとして、あなたは404エラーを取得してはならないルート値に

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

/文字が欠落しています。

ルートがアクション名と同じ場合は、 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', 
      ], 
     ], 
    ] 
関連する問題