Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZendFramework]404 dla wywołanej akcji
Forum PHP.pl > Forum > PHP > Frameworki
Bryla
Witam, zaczynam naukę Zend Framework z książki "Zend Framework 2.0 by Example" i od początku napotykam problemy. Mianowicie, mam stworzony moduł Users o takiej strukturze:


Kod kontrolera:
  1. <?php
  2. namespace Users\Controller;
  3.  
  4. use Zend\Mvc\Controller\AbstractActionController;
  5. use Zend\View\Model\ViewModel;
  6.  
  7. class IndexController extends AbstractActionController {
  8.  
  9. public function indexAction() {
  10. $view = new ViewModel();
  11. return $view;
  12. }
  13.  
  14. public function registerAction() {
  15. $view = new ViewModel();
  16. $view->setTemplate('users/index/new-user');
  17. return $view;
  18. }
  19.  
  20. public function loginAction() {
  21. $view = new ViewModel();
  22. $this->view->zmienna = 1;
  23. $view->setTemplate('users/index/login');
  24. return $view;
  25. }
  26. }


Kod pliku module.config.php:
  1. <?php
  2. /**
  3.  * Zend Framework (http://framework.zend.com/)
  4.  *
  5.  * @link <a href="http://github.com/zendframework/ZendSkeletonApplication" target="_blank">http://github.com/zendframework/ZendSkeletonApplication</a> for the canonical source repository
  6.  * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  7.  * @license <a href="http://framework.zend.com/license/new-bsd" target="_blank">http://framework.zend.com/license/new-bsd</a> New BSD License
  8.  */
  9.  
  10. return array(
  11. 'router' => array(
  12. 'routes' => array(
  13. 'users' => array (
  14. 'type' => 'Literal',
  15. 'options' => array(
  16. 'route' => '/users',
  17. 'defaults' => array (
  18. '__NAMESPACE__' => 'Users\Controller',
  19. 'controller' => 'Index',
  20. 'action' => 'index',
  21. ),
  22. ),
  23. ),
  24. 'home' => array(
  25. 'type' => 'Zend\Mvc\Router\Http\Literal',
  26. 'options' => array(
  27. 'route' => '/',
  28. 'defaults' => array(
  29. 'controller' => 'Application\Controller\Index',
  30. 'action' => 'index',
  31. ),
  32. ),
  33. ),
  34. // The following is a route to simplify getting started creating
  35. // new controllers and actions without needing to create a new
  36. // module. Simply drop new controllers in, and you can access them
  37. // using the path /application/:controller/:action
  38. 'application' => array(
  39. 'type' => 'Literal',
  40. 'options' => array(
  41. 'route' => '/application',
  42. 'defaults' => array(
  43. '__NAMESPACE__' => 'Application\Controller',
  44. 'controller' => 'Index',
  45. 'action' => 'index',
  46. ),
  47. ),
  48. 'may_terminate' => true,
  49. 'child_routes' => array(
  50. 'default' => array(
  51. 'type' => 'Segment',
  52. 'options' => array(
  53. 'route' => '/[:controller[/:action]]',
  54. 'constraints' => array(
  55. 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
  56. 'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
  57. ),
  58. 'defaults' => array(
  59. ),
  60. ),
  61. ),
  62. ),
  63. ),
  64. ),
  65. ),
  66. 'service_manager' => array(
  67. 'abstract_factories' => array(
  68. 'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
  69. 'Zend\Log\LoggerAbstractServiceFactory',
  70. ),
  71. 'aliases' => array(
  72. 'translator' => 'MvcTranslator',
  73. ),
  74. ),
  75. 'translator' => array(
  76. 'locale' => 'en_US',
  77. 'translation_file_patterns' => array(
  78. 'type' => 'gettext',
  79. 'base_dir' => __DIR__ . '/../language',
  80. 'pattern' => '%s.mo',
  81. ),
  82. ),
  83. ),
  84. 'controllers' => array(
  85. 'invokables' => array(
  86. 'Application\Controller\Index' => 'Application\Controller\IndexController',
  87. 'Users\Controller\Index' => 'Users\Controller\IndexController',
  88. ),
  89. ),
  90. 'view_manager' => array(
  91. 'template_path_stack' => array(
  92. __DIR__ . '/../view',
  93. 'users' => __DIR__ . '/../view'
  94. ),
  95. ),
  96. // Placeholder for console routes
  97. 'console' => array(
  98. 'router' => array(
  99. 'routes' => array(
  100. ),
  101. ),
  102. ),
  103. );


Widoki to zwykły kod HTML.

Problem polega na tym, że przy wejściu na adres : localhost/users/index/login dostaję błąd:
Cytat
A 404 error occurred
Page not found.
The requested URL could not be matched by routing.

No Exception available

Przy wejściu na localhost/users wszystko ładnie działa. Macie jakiś pomysł w czym może być przyczyna problemu?
aras785
Cześć. Z tego co widzę to już zdeklarowałeś routing dla tego controllera i akcji więc nie widzę nic dziwnego, że wszystko ładnie działa na localhost/users

  1. 'route' => '/users',
  2. 'defaults' => array (
  3. '__NAMESPACE__' => 'Users\Controller',
  4. 'controller' => 'Index',
  5. 'action' => 'index',
  6. ),


Popatrz na ten projekt:

https://github.com/akrabat/zf2-tutorial/blo...dule.config.php

Pozdrawiam
Bryla
Działa, dzięki smile.gif
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.