2017-08-26 2 views
1

J'utilise zf2 et j'ai défini des routes enfants comme celle-ci.La route enfant Zf2 ne fonctionne pas lorsqu'elle a un enfant de plus.

'routes' => array(
      'test' => array(
       'type' => 'Literal', 
       'options' => array(
        'route' => '/test', 
        'defaults' => array(
         '__NAMESPACE__' => 'Test\Controller', 
         'controller' => 'Test', 
         'action'  => 'index', 
        ), 
       ), 
       'may_terminate' => true, 
       'child_routes' => array(
        'testABC' => array(
          'type' => 'Literal', 
          'options' => array(
            'route' => '/abc', 
            'defaults' => array(
              'action'  => 'abc', 
            ), 
          ), 
          'child_routes' => array(
            'testABCDEF' => array(
              'type' => 'Segment', 
              'options' => array(
                'route' => '/def/:id', 
                'defaults' => array(
                  'action'  => 'def', 
                ), 
              ), 
            ), 
            'testABCXYZ' => array(
              'type' => 'Segment', 
              'options' => array(
                'route' => '/xyz/:id', 
                'defaults' => array(
                  'action'  => 'xyz', 
                ), 
              ), 
            ), 
          ), 
        ), 
       ), 
      ), 
     ), 

Dans ce seul chemin ne fonctionne pas, je ne sais pas pourquoi?

  • localhost/test travail
  • localhost/test/abc travail non
  • localhost/test/abc/def/1 travail
  • localhost/test/abc/xyz/1 Fonctionnement

Répondre

3

Le problème est dû au fait que votre testABC l'option may_terminate est manquante.

Si elle n'a pas d'enfant, il mettrait fin implicitement, mais comme il a des enfants, vous devez en informer le routeur de la possibilité explicitement (comme vous l'avez fait avec son itinéraire. Parent test)

'testABC' => array(
    'type' => 'Literal', 
    'options' => array(
     'route' => '/abc', 
     'defaults' => array(
      'action'  => 'abc', 
     ), 
    ), 
    'may_terminate' => true, // inform the router 
    'child_routes' => (
     // ... 
    ), 
), 
+0

grâce a beaucoup ... maintenant son fonctionnement..Maintenant je suis venu à savoir quelle est l'utilisation 'may_terminate'. – user3542450