2017-03-23 15 views
1

Ich bin neu bei Zend-Framework3.Kinderrouten funktionieren nicht

Und Migration meiner ZF2-Anwendung auf ZF3.

In diesem Kind funktionieren Routen nicht.

Hier Router von meinem 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' 
         ], 
        ], 
       ], 
      ] 
     ] 
    ], 
], 

Wenn ich versuche, /application/kk Aktion aufzurufen. Es generiert 404 error.

Wo liege ich falsch? Oder muss ich alle Aktionen manuell registrieren?

Antwort

3

... muss ich alle Aktionen manuell registrieren?

Nein, Sie fehlen nur / Charakter in Route Wert

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

Solange Aktion kk vorhanden ist, sollten Sie nicht 404 Fehler.

Wenn Ihre Routen identisch mit den Namen der Aktionen sind. Sie können Typ:

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