2017-09-16 1 views
1

Dans mon application, j'ai créé une seconde action dans un contrôleur. Quand j'appelle l'application avec l'url http://local.domain j'ai la bonne page donc c'est ce qu'on appelle le bon contrôleur. Mais si je veux faire cet appel http://local.domain/liga-futbol-1 cela ne fonctionne pas et je l'ai eu cette erreur:ZF3: Action et vue introuvables

A 404 error occurred Page not found. The requested URL could not be matched by routing.

No Exception available

IndexController.php

namespace Stats\Controller; 

use Zend\Mvc\Controller\AbstractActionController; 

class IndexController extends AbstractActionController { 
    public function indexAction() 
    { 
     //This action serves the page 
     return []; 
    } 

    public function ligaFubtol1Action(){ 

     return []; 
    } } 

module.config.php

namespace Stats; 

use Zend\Router\Http\Segment; 
use Zend\ServiceManager\Factory\InvokableFactory; 

return [ 
    'controllers' => [ 
     'factories' => [ 
      Controller\IndexController::class => InvokableFactory::class, 
     ], 
    ], 
    'router' => [ 
     'routes' => [ 
      'home' => [ 
       'type' => 'Literal', 
       'options' => [ 
        // This works!!! => http://local.domain 
        'route' => '/', 
        'defaults' => [ 
         'controller' => Controller\IndexController::class, 
         'action'  => 'index', 
        ], 
       ], 
       'may_terminate' => true, 
       'child_routes' => [ 
        // This doesn't work!!! http://local.domain/liga-futbol-1 
        'liga-futbol-1' => [ 
         'type' => Segment::class, 
         'options' => [ 
          'route' => '/liga-futbol-1', 
          'defaults' => [ 
           'controller' => Controller\IndexController::class, 
           'action'  => 'ligaFutbol1' 
          ], 
         ], 
         'may_terminate' => true, 
         'child_routes' => [ 
         ], 
        ],      
       ], 
      ],  
     ], 
    ], 
    'view_manager' => [ 
     'display_not_found_reason' => true, 
     'display_exceptions'  => true, 
     'doctype'     => 'HTML5', 
     'not_found_template'  => 'error/404', 
     'exception_template'  => 'error/index', 
     'template_map' => [ 
      'layout/layout'   => __DIR__ . '/../view/layout/layout.phtml', 
      'stats/index/index'  => __DIR__ . '/../view/stats/index/index.phtml', 
      'error/404'    => __DIR__ . '/../view/error/404.phtml', 
      'error/index'    => __DIR__ . '/../view/error/index.phtml', 
     ], 
     'template_path_stack' => [ 
      __DIR__ . '/../view', 
     ], 
     /* 
     * Con este array de parámetros permitimos enviar datos y no mostrar vista 
     */ 
     'strategies' => [ 
      'ViewJsonStrategy', 
     ],   
    ], 
]; 

Annuaires:

enter image description here

J'ai vérifié mon cache dans "/ dir_project/data/cache" et il n'y a rien.

Qu'est-ce que je fais mal?

Répondre

3

Jetez un oeil à l'option route de la route home: il est réglé sur /. La route liga-futbol-1 est un itinéraire de l'enfant de la route home, de sorte que son URL est une « somme » de:

  • home URL: /
  • liga-futbol-1 URL: /liga-futbol-1

En résultat: //liga-futbol-1 est l'URL de la route home/liga-futbol-1.

Si vous voulez juste quelque chose comme /liga-futbol-1, il y a deux solutions:

  1. Faire la voie indépendante de liga-futbol-1 de la route home (c.-à-pas son enfant):

    'routes' => [ 
        'home' => [ 
         'type' => Literal::class, 
         'options' => [ 
          'route' => '/', 
          'defaults' => [ 
           'controller' => Controller\IndexController::class, 
           'action'  => 'index' 
          ] 
         ] 
        ], 
        'liga-futbol-1' => [ 
         'type' => Segment::class, 
         'options' => [ 
          'route' => '/liga-futbol-1', 
          'defaults' => [ 
           'controller' => Controller\IndexController::class, 
           'action'  => 'ligaFutbol1' 
          ] 
         ] 
        ] 
    ] 
    
  2. Retirer / à partir du début liga-futbol-1route option:

    'liga-futbol-1' => [ 
        'type' => Segment::class, 
        'options' => [ 
         'route' => 'liga-futbol-1', 
          'defaults' => [ 
           'controller' => Controller\IndexController::class, 
           'action'  => 'ligaFutbol1' 
          ] 
         ] 
        ] 
    
+0

Cela fonctionne !!! Merci beaucoup @gsc !!! Un million de merci !!! –