Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [zf] problem z routingem
Forum PHP.pl > Forum > PHP > Frameworki
netvalue
Witam,
nie moge wywowalac adresu "http://localhost/products/edit"
otrzymuje blad "A 404 error occurred Page not found.The requested URL could not be matched by routing.No Exception available"

Oczywiscie mam metody edit w klasie kontrolera Products oraz widok html

  1. return array(
  2. 'router' => array(
  3. 'routes' => array(
  4. 'home' => array(
  5. 'type' => 'Zend\Mvc\Router\Http\Literal',
  6. 'options' => array(
  7. 'route' => '/',
  8. 'defaults' => array(
  9. 'controller' => 'Application\Controller\Index',
  10. 'action' => 'index',
  11. ),
  12. ),
  13. ),
  14.  
  15. 'application' => array(
  16. 'type' => 'Literal',
  17. 'options' => array(
  18. 'route' => '/application',
  19. 'defaults' => array(
  20. '__NAMESPACE__' => 'Application\Controller',
  21. 'controller' => 'Index',
  22. 'action' => 'index',
  23. ),
  24. ),
  25. 'may_terminate' => true,
  26. 'child_routes' => array(
  27. 'default' => array(
  28. 'type' => 'Segment',
  29. 'options' => array(
  30. 'route' => '/application[/:action]',
  31. 'constraints' => array(
  32. 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
  33. 'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
  34. ),
  35. 'defaults' => array(
  36. ),
  37. ),
  38. ),
  39. ),
  40. ),
  41. 'products' => array(
  42. 'type' => 'Literal',
  43. 'options' => array(
  44. 'route' => '/products',
  45. 'defaults' => array(
  46. '__NAMESPACE__' => 'Application\Controller',
  47. 'controller' => 'Products',
  48. 'action' => 'index',
  49. ),
  50. ),
  51. 'may_terminate' => true,
  52. 'child_routes' => array(
  53. 'default' => array(
  54. 'type' => 'Segment',
  55. 'options' => array(
  56. 'route' => '/products[/:action]',
  57. 'constraints' => array(
  58. 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
  59. 'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
  60. ),
  61. 'defaults' => array(
  62. ),
  63. ),
  64. ),
  65. ),
  66. ),
  67. ),
  68. ),
  69. 'service_manager' => array(
  70. 'abstract_factories' => array(
  71. 'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
  72. 'Zend\Log\LoggerAbstractServiceFactory',
  73. ),
  74. 'aliases' => array(
  75. 'translator' => 'MvcTranslator',
  76. ),
  77. ),
  78. 'translator' => array(
  79. 'locale' => 'en_EN',
  80. 'translation_file_patterns' => array(
  81. 'type' => 'gettext',
  82. 'base_dir' => __DIR__ . '/../language',
  83. 'pattern' => '%s.mo',
  84. ),
  85. ),
  86. ),
  87. 'controllers' => array(
  88. 'invokables' => array(
  89. 'Application\Controller\Index' => 'Application\Controller\IndexController',
  90. 'Application\Controller\Products' => 'Application\Controller\ProductsController'
  91. )
  92.  
  93. ),
  94. 'view_manager' => array(
  95. 'display_not_found_reason' => true,
  96. 'display_exceptions' => true,
  97. 'doctype' => 'HTML5',
  98. 'not_found_template' => 'error/404',
  99. 'exception_template' => 'error/index',
  100. 'template_map' => array(
  101. 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
  102. 'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
  103. 'error/404' => __DIR__ . '/../view/error/404.phtml',
  104. 'error/index' => __DIR__ . '/../view/error/index.phtml',
  105. ),
  106. 'template_path_stack' => array(
  107. __DIR__ . '/../view',
  108. ),
  109. ),
  110. // Placeholder for console routes
  111. 'console' => array(
  112. 'router' => array(
  113. 'routes' => array(
  114. ),
  115. ),
  116. ),
  117. );
  118.  
sf
Zamiast 'route' => '/products[/:action]', spróbuj 'route' => '[/:action]',
em1X
Cytat(sf @ 8.05.2014, 07:56:34 ) *
Zamiast 'route' => '/products[/:action]', spróbuj 'route' => '[/:action]',


raczej 'route' => '/:action'

btw.

1) wywal `controller` z constraints skoro go nie używasz
2) po co tworzyć nowy route products skoro spokojnie wystarczyłby lekko przerobiony route application/default z: 'route' => '/application[/:action]' na 'route' => '/:controller[/:action]',
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.