Zend FR

Consultez la FAQ sur le ZF avant de poster une question

Vous n'êtes pas identifié.

#1 04-06-2014 16:07:36

jean
Membre
Date d'inscription: 25-08-2008
Messages: 107

[Résolu] Problème de routage pour accéder à une vue

Bonjour,

Je débute avec ZF2 et j'ai créé un nouveau module 'Users'.

Lorsque j'accède à l'appli (http://tool) , je vois la vue module : Users,  controller : Index, vue : index

Par contre, je n'arrive pas à accéder aux autres vues de mon controller Index (ex: http://tool/users/index/login retourne une erreur 404). Les actions sont créées et les autres vues sont bien créées au même emplacement que ma vue index.phtml

Comme j'ai installé ZendDeveloperTool, voici la ApplicationConfig et la Config.

Avez-vous une idée ?

Code:

array(2) {
  ["modules"] => array(4) {
    [0] => string(11) "Application"
    [1] => string(5) "Users"
    [2] => string(18) "ZendDeveloperTools"
    [3] => string(11) "BjyProfiler"
  }
  ["module_listener_options"] => array(2) {
    ["module_paths"] => array(2) {
      [0] => string(8) "./module"
      [1] => string(8) "./vendor"
    }
    ["config_glob_paths"] => array(1) {
      [0] => string(39) "config/autoload/{,*.}{global,local}.php"
    }
  }
}

Code:

array(7) {
  ["router"] => array(1) {
    ["routes"] => array(3) {
      ["home"] => array(2) {
        ["type"] => string(28) "Zend\Mvc\Router\Http\Literal"
        ["options"] => array(2) {
          ["route"] => string(1) "/"
          ["defaults"] => array(2) {
            ["controller"] => string(22) "Users\Controller\Index"
            ["action"] => string(5) "index"
          }
        }
      }
      ["application"] => array(4) {
        ["type"] => string(7) "Literal"
        ["options"] => array(2) {
          ["route"] => string(12) "/application"
          ["defaults"] => array(3) {
            ["__NAMESPACE__"] => string(22) "Application\Controller"
            ["controller"] => string(5) "Index"
            ["action"] => string(5) "index"
          }
        }
        ["may_terminate"] => bool(true)
        ["child_routes"] => array(1) {
          ["default"] => array(2) {
            ["type"] => string(7) "Segment"
            ["options"] => array(3) {
              ["route"] => string(24) "/[:controller[/:action]]"
              ["constraints"] => array(2) {
                ["controller"] => string(22) "[a-zA-Z][a-zA-Z0-9_-]*"
                ["action"] => string(22) "[a-zA-Z][a-zA-Z0-9_-]*"
              }
              ["defaults"] => array(0) {
              }
            }
          }
        }
      }
      ["users"] => array(4) {
        ["type"] => string(7) "Literal"
        ["options"] => array(2) {
          ["route"] => string(6) "/users"
          ["defaults"] => array(3) {
            ["__NAMESPACE__"] => string(16) "Users\Controller"
            ["controller"] => string(5) "Index"
            ["action"] => string(5) "index"
          }
        }
        ["may_terminate"] => bool(true)
        ["child_route"] => array(1) {
          ["default"] => array(2) {
            ["type"] => string(7) "Segment"
            ["options"] => array(3) {
              ["route"] => string(30) "/[:controller[/:action]][/:id]"
              ["constraints"] => array(3) {
                ["controller"] => string(22) "[a-zA-Z][a-zA-Z0-9_-]*"
                ["action"] => string(22) "[a-zA-Z][a-zA-Z0-9_-]*"
                ["id"] => string(6) "[0-9]+"
              }
              ["defaults"] => array(0) {
              }
            }
          }
        }
      }
    }
  }
  ["service_manager"] => array(3) {
    ["abstract_factories"] => array(2) {
      [0] => string(53) "Zend\Cache\Service\StorageCacheAbstractServiceFactory"
      [1] => string(37) "Zend\Log\LoggerAbstractServiceFactory"
    }
    ["aliases"] => array(1) {
      ["translator"] => string(13) "MvcTranslator"
    }
    ["factories"] => array(1) {
      ["Zend\Db\Adapter\Adapter"] => object(Closure)#327 (1) {
        ["this"] => object(ZendDeveloperTools\Collector\ConfigCollector)#311 (2) {
          ["config":protected] => array(7) {
            ["router"] => array(1) {
              ["routes"] => array(3) {
                ["home"] => array(2) {
                  ["type"] => string(28) "Zend\Mvc\Router\Http\Literal"
                  ["options"] => array(2) {
                    ["route"] => string(1) "/"
                    ["defaults"] => array(2) {
                      ["controller"] => string(22) "Users\Controller\Index"
                      ["action"] => string(5) "index"
                    }
                  }
                }
                ["application"] => array(4) {
                  ["type"] => string(7) "Literal"
                  ["options"] => array(2) {
                    ["route"] => string(12) "/application"
                    ["defaults"] => array(3) {
                      ["__NAMESPACE__"] => string(22) "Application\Controller"
                      ["controller"] => string(5) "Index"
                      ["action"] => string(5) "index"
                    }
                  }
                  ["may_terminate"] => bool(true)
                  ["child_routes"] => array(1) {
                    ["default"] => array(2) {
                      ["type"] => string(7) "Segment"
                      ["options"] => array(3) {
                        ["route"] => string(24) "/[:controller[/:action]]"
                        ["constraints"] => array(2) {
                          ["controller"] => string(22) "[a-zA-Z][a-zA-Z0-9_-]*"
                          ["action"] => string(22) "[a-zA-Z][a-zA-Z0-9_-]*"
                        }
                        ["defaults"] => array(0) {
                        }
                      }
                    }
                  }
                }
                ["users"] => array(4) {
                  ["type"] => string(7) "Literal"
                  ["options"] => array(2) {
                    ["route"] => string(6) "/users"
                    ["defaults"] => array(3) {
                      ["__NAMESPACE__"] => string(16) "Users\Controller"
                      ["controller"] => string(5) "Index"
                      ["action"] => string(5) "index"
                    }
                  }
                  ["may_terminate"] => bool(true)
                  ["child_route"] => array(1) {
                    ["default"] => array(2) {
                      ["type"] => string(7) "Segment"
                      ["options"] => array(3) {
                        ["route"] => string(30) "/[:controller[/:action]][/:id]"
                        ["constraints"] => array(3) {
                          ["controller"] => string(22) "[a-zA-Z][a-zA-Z0-9_-]*"
                          ["action"] => string(22) "[a-zA-Z][a-zA-Z0-9_-]*"
                          ["id"] => string(6) "[0-9]+"
                        }
                        ["defaults"] => array(0) {
                        }
                      }
                    }
                  }
                }
              }
            }
            ["service_manager"] => array(3) {
              ["abstract_factories"] => array(2) {
                [0] => string(53) "Zend\Cache\Service\StorageCacheAbstractServiceFactory"
                [1] => string(37) "Zend\Log\LoggerAbstractServiceFactory"
              }
              ["aliases"] => array(1) {
                ["translator"] => string(13) "MvcTranslator"
              }
              ["factories"] => array(1) {
                ["Zend\Db\Adapter\Adapter"] => object(ZendDeveloperTools\Stub\ClosureStub)#312 (0) {
                }
              }
            }
            ["translator"] => array(2) {
              ["locale"] => string(5) "en_US"
              ["translation_file_patterns"] => array(1) {
                [0] => array(4) {
                  ["type"] => string(7) "gettext"
                  ["base_dir"] => string(57) "C:\travail\www\tool\module\Application\config/../language"
                  ["pattern"] => string(5) "%s.mo"
                  ["text_domain"] => string(0) ""
                }
              }
            }
            ["controllers"] => array(1) {
              ["invokables"] => array(2) {
                ["Application\Controller\Index"] => string(38) "Application\Controller\IndexController"
                ["Users\Controller\Index"] => string(32) "Users\Controller\IndexController"
              }
            }
            ["view_manager"] => array(7) {
              ["display_not_found_reason"] => bool(true)
              ["display_exceptions"] => bool(true)
              ["doctype"] => string(5) "HTML5"
              ["not_found_template"] => string(9) "error/404"
              ["exception_template"] => string(11) "error/index"
              ["template_map"] => array(4) {
                ["layout/layout"] => string(73) "C:\travail\www\tool\module\Application\config/../view/layout/layout.phtml"
                ["application/index/index"] => string(83) "C:\travail\www\tool\module\Application\config/../view/application/index/index.phtml"
                ["error/404"] => string(69) "C:\travail\www\tool\module\Application\config/../view/error/404.phtml"
                ["error/index"] => string(71) "C:\travail\www\tool\module\Application\config/../view/error/index.phtml"
              }
              ["template_path_stack"] => array(3) {
                [0] => string(53) "C:\travail\www\tool\module\Application\config/../view"
                ["users"] => string(47) "C:\travail\www\tool\module\Users\config/../view"
                ["zenddevelopertools"] => string(60) "C:\travail\www\tool\module\ZendDeveloperTools\config/../view"
              }
            }
            ["console"] => array(1) {
              ["router"] => array(1) {
                ["routes"] => array(0) {
                }
              }
            }
            ["zenddevelopertools"] => array(3) {
              ["profiler"] => array(6) {
                ["enabled"] => bool(true)
                ["strict"] => bool(true)
                ["flush_early"] => bool(false)
                ["cache_dir"] => string(10) "data/cache"
                ["matcher"] => array(0) {
                }
                ["collectors"] => array(0) {
                }
              }
              ["events"] => array(3) {
                ["enabled"] => bool(true)
                ["collectors"] => array(0) {
                }
                ["identifiers"] => array(0) {
                }
              }
              ["toolbar"] => array(5) {
                ["enabled"] => bool(true)
                ["auto_hide"] => bool(false)
                ["position"] => string(6) "bottom"
                ["version_check"] => bool(false)
                ["entries"] => array(0) {
                }
              }
            }
          }
          ["applicationConfig":protected] => array(2) {
            ["modules"] => array(4) {
              [0] => string(11) "Application"
              [1] => string(5) "Users"
              [2] => string(18) "ZendDeveloperTools"
              [3] => string(11) "BjyProfiler"
            }
            ["module_listener_options"] => array(2) {
              ["module_paths"] => array(2) {
                [0] => string(8) "./module"
                [1] => string(8) "./vendor"
              }
              ["config_glob_paths"] => array(1) {
                [0] => string(39) "config/autoload/{,*.}{global,local}.php"
              }
            }
          }
        }
      }
    }
  }
  ["translator"] => array(2) {
    ["locale"] => string(5) "en_US"
    ["translation_file_patterns"] => array(1) {
      [0] => array(4) {
        ["type"] => string(7) "gettext"
        ["base_dir"] => string(57) "C:\travail\www\tool\module\Application\config/../language"
        ["pattern"] => string(5) "%s.mo"
        ["text_domain"] => string(0) ""
      }
    }
  }
  ["controllers"] => array(1) {
    ["invokables"] => array(2) {
      ["Application\Controller\Index"] => string(38) "Application\Controller\IndexController"
      ["Users\Controller\Index"] => string(32) "Users\Controller\IndexController"
    }
  }
  ["view_manager"] => array(7) {
    ["display_not_found_reason"] => bool(true)
    ["display_exceptions"] => bool(true)
    ["doctype"] => string(5) "HTML5"
    ["not_found_template"] => string(9) "error/404"
    ["exception_template"] => string(11) "error/index"
    ["template_map"] => array(4) {
      ["layout/layout"] => string(73) "C:\travail\www\tool\module\Application\config/../view/layout/layout.phtml"
      ["application/index/index"] => string(83) "C:\travail\www\tool\module\Application\config/../view/application/index/index.phtml"
      ["error/404"] => string(69) "C:\travail\www\tool\module\Application\config/../view/error/404.phtml"
      ["error/index"] => string(71) "C:\travail\www\tool\module\Application\config/../view/error/index.phtml"
    }
    ["template_path_stack"] => array(3) {
      [0] => string(53) "C:\travail\www\tool\module\Application\config/../view"
      ["users"] => string(47) "C:\travail\www\tool\module\Users\config/../view"
      ["zenddevelopertools"] => string(60) "C:\travail\www\tool\module\ZendDeveloperTools\config/../view"
    }
  }
  ["console"] => array(1) {
    ["router"] => array(1) {
      ["routes"] => array(0) {
      }
    }
  }
  ["zenddevelopertools"] => array(3) {
    ["profiler"] => array(6) {
      ["enabled"] => bool(true)
      ["strict"] => bool(true)
      ["flush_early"] => bool(false)
      ["cache_dir"] => string(10) "data/cache"
      ["matcher"] => array(0) {
      }
      ["collectors"] => array(0) {
      }
    }
    ["events"] => array(3) {
      ["enabled"] => bool(true)
      ["collectors"] => array(0) {
      }
      ["identifiers"] => array(0) {
      }
    }
    ["toolbar"] => array(5) {
      ["enabled"] => bool(true)
      ["auto_hide"] => bool(false)
      ["position"] => string(6) "bottom"
      ["version_check"] => bool(false)
      ["entries"] => array(0) {
      }
    }
  }
}

Cordialement,

Dernière modification par jean (06-06-2014 12:45:30)

Hors ligne

 

#2 05-06-2014 08:46:22

flobrflo
Membre
Lieu: Marseille
Date d'inscription: 26-04-2013
Messages: 376

Re: [Résolu] Problème de routage pour accéder à une vue

Hello,
déjà je te déconseils d'utiliser les paramètres [:controller[/:action]], il vaut mieux faire plus de routes plus précises
(j'en dirais pas plus, je te laisse chercher, y a pleins de topucs traitant le sujet ici ^^)


A tu une 404 sur la route /users aussi?

Hors ligne

 

#3 06-06-2014 12:43:43

jean
Membre
Date d'inscription: 25-08-2008
Messages: 107

Re: [Résolu] Problème de routage pour accéder à une vue

Tu as raison : c'est mieux avec la doc  ! 

Voici la route qui "fonctionne", avec des routes plus précises.
J'ai commenté au début pour ceux que cela intéresse.

Code:

<?php
/*
 * La config est passée à tous les composants par le ServieManager
 * Les deux sections controllers et view_manager indiquent la liste de tous 
 * les controllers du module.
 * 
 * ATTENTION : le module => Users (avec "s")
 *             la route  => user  (sans "s")
 * 
 * Le controller IndexController sera référencé User\Controller\Index
 * Comme le nom du controller doit être unique, il sera préfixé par le nom du module.
 *
 *  Appel de la route : http://<appli>/<route>/<child_route>/<parametre...>
 */

return array(
    'controllers' => array(
        'invokables' => array(
            'Users\Controller\Index' => 'Users\Controller\IndexController',
        ),
    ),
    'router' => array(
        'routes' => array(
            'user' => array(
                'type' => 'Literal',
                'options' => array(
                    // Change this to something specific to your module
                    'route' => '/user',
                    'defaults' => array(
                        // Change this value to reflect the namespace in which
                        // the controllers for your module are found
                        '__NAMESPACE__' => 'Users\Controller',
                        'controller' => 'Index',
                        'action' => 'index'
                    )
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'login' => array(
                        'type' => 'Literal',
                        'options' => array(
                            'route' => '/login',
                            'defaults' => array(
                                'action' => 'login'
                            )
                        ),
                        'verb' => 'get,post'
                    ),
                    'register' => array(
                        'type' => 'Literal',
                        'options' => array(
                            'route' => '/register',
                            'defaults' => array(
                                'action' => 'register'
                            )
                        ),
                        'verb' => 'get,post'
                    ),
                ),
            ),
        ),
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'album' => __DIR__ . '/../view',
        ),
    ),
);

Dernière modification par jean (06-06-2014 12:44:20)

Hors ligne

 

Pied de page des forums

Propulsé par PunBB
© Copyright 2002–2005 Rickard Andersson
Traduction par punbb.fr

Graphisme réalisé par l'agence Rodolphe Eveilleau
Développement par Kitpages