Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZendFramework][ZendFramework2] Routing w formularzu.
Forum PHP.pl > Forum > PHP > Frameworki
istrd
Witam,
Mam problem z wygenerowaniem routingu. Tworzę formularz. W templatce chcę ustawić akcje, do której ma być wysłany formularz. Chciałbym wygenerować taki url " localhost/public/application/index/convert"
Pod tą akcje mogę wejść i dostaje akcje convert. Plik module.config.php jest standardowy (projekt dopiero utworzony)

Ustawienie w templatce:
  1. $form = $this->form;
  2. $form->setAttribute('action', $this->url('application/index', array('action' => 'convert')));
  3. $form->prepare();


Plik z routingiem
  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. 'home' => array(
  14. 'type' => 'Zend\Mvc\Router\Http\Literal',
  15. 'options' => array(
  16. 'route' => '/',
  17. 'defaults' => array(
  18. 'controller' => 'Application\Controller\Index',
  19. 'action' => 'index',
  20. ),
  21. ),
  22. ),
  23. // The following is a route to simplify getting started creating
  24. // new controllers and actions without needing to create a new
  25. // module. Simply drop new controllers in, and you can access them
  26. // using the path /application/:controller/:action
  27. 'application' => array(
  28. 'type' => 'Literal',
  29. 'options' => array(
  30. 'route' => '/application',
  31. 'defaults' => array(
  32. '__NAMESPACE__' => 'Application\Controller',
  33. 'controller' => 'Index',
  34. 'action' => 'index',
  35. ),
  36. ),
  37. 'may_terminate' => true,
  38. 'child_routes' => array(
  39. 'default' => array(
  40. 'type' => 'Segment',
  41. 'options' => array(
  42. 'route' => '/[:controller[/:action]]',
  43. 'constraints' => array(
  44. 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
  45. 'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
  46. ),
  47. 'defaults' => array(
  48. ),
  49. ),
  50. ),
  51. ),
  52. ),
  53. ),
  54. ),
  55. 'service_manager' => array(
  56. 'abstract_factories' => array(
  57. 'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
  58. 'Zend\Log\LoggerAbstractServiceFactory',
  59. ),
  60. 'aliases' => array(
  61. 'translator' => 'MvcTranslator',
  62. ),
  63. ),
  64. 'translator' => array(
  65. 'locale' => 'en_US',
  66. 'translation_file_patterns' => array(
  67. 'type' => 'gettext',
  68. 'base_dir' => __DIR__ . '/../language',
  69. 'pattern' => '%s.mo',
  70. ),
  71. ),
  72. ),
  73. 'controllers' => array(
  74. 'invokables' => array(
  75. 'Application\Controller\Index' => 'Application\Controller\IndexController'
  76. ),
  77. ),
  78. 'view_manager' => array(
  79. 'display_not_found_reason' => true,
  80. 'display_exceptions' => true,
  81. 'doctype' => 'HTML5',
  82. 'not_found_template' => 'error/404',
  83. 'exception_template' => 'error/index',
  84. 'template_map' => array(
  85. 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
  86. 'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
  87. 'error/404' => __DIR__ . '/../view/error/404.phtml',
  88. 'error/index' => __DIR__ . '/../view/error/index.phtml',
  89. ),
  90. 'template_path_stack' => array(
  91. __DIR__ . '/../view',
  92. ),
  93. ),
  94. // Placeholder for console routes
  95. 'console' => array(
  96. 'router' => array(
  97. 'routes' => array(
  98. ),
  99. ),
  100. ),
  101. );
solr
  1. $form->setAttribute('action', $this->url('application/default', array('action' => 'convert')));


Pierwszy parametr identyfikuje routing (u Ciebie bedzie to na podstawie linii 27 i 39). Kontrolera nie musisz podawac w drugim parametrze, ale akcje chcesz juz inna niz domyslna (convert), wiec trzeba.
istrd
niestety w form action mam
  1. action="/public/application/"
Próbowałem kilka sposobów lecz nic nie wychodzi. Jakieś inne propozycje?
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.