Zend_Controller-Migration.xml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.controller.migration">
  4. <title>Migración de versiones anteriores</title>
  5. <para>
  6. La API de los componentes de MVC ha cambiado en el tiempo. Si usted ha empezado a
  7. usar una versión anterior de Zend Framework, sigua la guía de abajo para
  8. migrar sus acripts para usar la arquitectura nueva.
  9. </para>
  10. <sect2 id="zend.controller.migration.fromonesixtooneseven">
  11. <title>Migración de 1.6.x a 1.7.0 o nuevas versiones</title>
  12. <sect3 id="zend.controller.migration.fromonesixtooneseven.dispatcher">
  13. <title>El despachador de la interfaz cambios</title>
  14. <para>
  15. Los usuarios llamaron nuestra atención el hecho de que
  16. <classname> Zend_Controller_Action_Helper_ViewRenderer </classname> estaba
  17. utilizando un método despachador de la clase abstracta que no está en
  18. el despachador de la interfaz. Hemos añadido el siguiente método para
  19. garantizar que los despachadores de costumbre seguirán trabajando con las
  20. implementaciones enviadas:
  21. </para>
  22. <itemizedlist>
  23. <listitem><para>
  24. <code>formatModuleName()</code>: debe utilizarse para tomar un nuevo
  25. nombre de controlador, tal como uno que deberia estar basado dentro de una petición
  26. objeto, y cambiarlo a un nombre de clase apropiado que la clase extendida
  27. <classname>Zend_Controller_Action</classname> deberia usar
  28. </para></listitem>
  29. </itemizedlist>
  30. </sect3>
  31. </sect2>
  32. <sect2 id="zend.controller.migration.fromoneohtoonesix">
  33. <title>Migrando desde 1.5.x to 1.6.0 o versiones posteriores</title>
  34. <sect3 id="zend.controller.migration.fromoneohtoonesix.dispatcher">
  35. <title>El Despachador de la Interfaz de cambios</title>
  36. <para>
  37. Los usuarios atrajeron nuestra atención con el hecho de que
  38. <classname> Zend_Controller_Front </classname> y
  39. <classname> Zend_Controller_Router_Route_Module </classname> fueron
  40. utilizando métodos del despachador que no estaban en la interfaz del
  41. despachador. Ahora hemos adicionado los siguientes tres métodos para
  42. asegurar que los despachadores diseñados sigan trabajando con las
  43. implementaciones enviadas:
  44. </para>
  45. <itemizedlist>
  46. <listitem><para>
  47. <code>getDefaultModule()</code>: debe retornar el nombre del
  48. módulo por defecto.
  49. </para></listitem>
  50. <listitem><para>
  51. <code>getDefaultControllerName()</code>: debe retornar el
  52. nombre del controlador por defecto.
  53. </para></listitem>
  54. <listitem><para>
  55. <code>getDefaultAction()</code>: debe retornar el
  56. nombre de la acción por defecto.
  57. </para></listitem>
  58. </itemizedlist>
  59. </sect3>
  60. </sect2>
  61. <sect2 id="zend.controller.migration.fromoneohtoonefive">
  62. <title>Migranado desde 1.0.x a 1.5.0 o versiones posteriores</title>
  63. <para>
  64. Aunque la mayoría de la funcionalidad básica sigue siendo la misma, y todas las
  65. funcionalidades documentadas siguen siendo la mismas, hay una en particular
  66. "característica" <emphasis>undocumented</emphasis> que ha cambiado.
  67. </para>
  68. <para>
  69. Al escribir las URLs, la manera de escribir la documentada acción camelCased
  70. es usar un separador de palabra, que son "." o '-' por defecto,
  71. pero pueden ser configurados en el despachador. El despachador internamente
  72. convierte en minúsculas el nombre de la acción, y usa estos separadores de palabra para
  73. volver a montar el método de la acción camelCasing. Sin embargo, debido a que las
  74. funciones de PHP no son sensibles a mayúsculas y minúsculas, usted <emphasis>podría</emphasis>
  75. escribir las URLs usando camelCasing, y el despachador los devolvería
  76. a la misma ubicación. Por ejemplo, 'camel-cased' se convertirá en
  77. 'camelCasedAction' por el despachador, mientras que 'camelCased' se
  78. convertiría en 'camelCasedAction'; sin embargo, debido a la insensibilidad de
  79. PHP, ambos ejecutarán el mismo método.
  80. </para>
  81. <para>
  82. Esto causa problemas con la vista ViewRenderer cuando devuelve scripts de la
  83. vista. El canónico, la documentada forma es que todos los separadores de palabra
  84. se conviertan en guiones, y las palabras en minúsculas. Esto crea
  85. un lazo semántico entre las acciones y los scripts de las vistas, y la
  86. normalización asegura que los scripts puedan ser encontrados. Sin embargo, si la
  87. acción "camelCased' es llamada y de hecho retornada, el separador de la palabra
  88. no está mas presente, y los ViewRenderer intenta devolver
  89. a una ubicación diferente -- 'camelcased.phtml' en vez de
  90. 'camel-cased.phtml'.
  91. </para>
  92. <para>
  93. Algunos desarrolladores se basarón en esta "característica", que nunca fue la intención.
  94. Varios cambios en el árbol 1.5.0 , sin embargo, hizo que la vista
  95. ViewRenderer ya no resuelva estas direcciones, la semántica esta ahora
  96. forzada. La primera de ellas, el despachador ahora impone
  97. la sensibilidad en los nombres de la acción. Lo que esto significa es que la referencia a
  98. sus acciones en la url utilisando camelCasing ya no para devolver
  99. al mismo método que utilizan los separadores de palabras (es decir, 'camel-casing').
  100. Esto nos lleva a la vista ViewRenderer ahora sólo en honor a las acciones
  101. palabra-separador cuando se devuleven los scripts vista.
  102. </para>
  103. <para>
  104. Si usted nota que estaba dependiendo en esta "caracteristica", usted tiene muchas
  105. opciones:
  106. </para>
  107. <itemizedlist>
  108. <listitem><para>
  109. Mejor opción: cambiar el nombre de sus scripts de la vistas. Pros:
  110. compatibilidad hacia adelante. Contras: si usted tiene muchos scripts vista que
  111. se basan en la primera vista, una conducta no deseada, tendrá
  112. mucho por hacer.
  113. </para></listitem>
  114. <listitem>
  115. <para>
  116. Segunda mejor opción: La vista ViewRenderer delega ahora resoluciones de scripts
  117. de vistas a <classname> Zend_Filter_Inflector </classname>; se puede
  118. modificar las normas del inflector para que ya no separe
  119. las palabras de una acción con un guión:
  120. </para>
  121. <programlisting role="php"><![CDATA[
  122. $viewRenderer =
  123. Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
  124. $inflector = $viewRenderer->getInflector();
  125. $inflector->setFilterRule(':action', array(
  126. new Zend_Filter_PregReplace(
  127. '#[^a-z0-9' . preg_quote(DIRECTORY_SEPARATOR, '#') . ']+#i',
  128. ''
  129. ),
  130. 'StringToLower'
  131. ));
  132. ]]></programlisting>
  133. <para>
  134. El anterior código modificará el inflector para que ya no
  135. separe las palabras con guión, usted puede querer eliminar
  136. el filtro 'StringToLower' si usted desea<emphasis>hacer</emphasis>
  137. el nombre de script de vista actual camelCased también.
  138. </para>
  139. <para>
  140. Si cambiar el nombre del script vista sería demasiado tedioso o tiempo
  141. consumido, esta es su mejor opción hasta que pueda encontrar el
  142. tiempo para hacerlo.
  143. </para>
  144. </listitem>
  145. <listitem>
  146. <para>
  147. La opción menos deseable: Usted puede forzar al despachador para
  148. despachar nombres de acción camelCased con un nuevo controlador
  149. bandera, 'useCaseSensitiveActions':
  150. </para>
  151. <programlisting role="php"><![CDATA[
  152. $front->setParam('useCaseSensitiveActions', true);
  153. ]]></programlisting>
  154. <para>
  155. Esto le permitirá utilizar camelCasing sobre la url y siguir
  156. tieniendo resuelta la misma acción como cuando se utilizaba los separadores
  157. de palabra. Sin embargo, esto significa que los problemas originales
  158. se iran terminando, lo más probable es utilizar la
  159. segunda opción anterior, además de esto para que las cosas funcionen
  160. confiablemente en todo.
  161. </para>
  162. <para>
  163. Note, también, el uso de esta bandera aumentará un aviso de que
  164. este uso es obsoleto.
  165. </para>
  166. </listitem>
  167. </itemizedlist>
  168. </sect2>
  169. <sect2 id="zend.controller.migration.fromzeroninethree">
  170. <title>Migrando desde 0.9.3 a 1.0.0RC1 o versiones posteriores</title>
  171. <para>
  172. Los cambios principales introducidos en 1.0.0RC1 son la introducción de
  173. y la activación por defecto del plugin
  174. <link
  175. linkend="zend.controller.plugins.standard.errorhandler">ErrorHandler</link>
  176. y de acción ayuda <link
  177. linkend="zend.controller.actionhelpers.viewrenderer">ViewRenderer</link>
  178. Por favor, lea la documentación de cada uno completamente para ver
  179. cómo funcionan y qué efecto pueden tener en sus
  180. aplicaciones.
  181. </para>
  182. <para>
  183. El plugin <code>ErrorHandler</code> corre durante
  184. <code>postDispatch ()</code> para el control de excepciones, y enviarlo
  185. a un especifico controlador de errores. Usted debe incluir tal
  186. controlador en su aplicación. Usted puede desactivarlo determinando el
  187. parámetro del controlador <code> noErrorHandler </code>:
  188. </para>
  189. <programlisting role="php"><![CDATA[
  190. $front->setParam('noErrorHandler', true);
  191. ]]></programlisting>
  192. <para>
  193. La acción de ayuda <code>ViewRenderer</code> automatiza inyección de vistas
  194. en controladores de acción así como los autogeneradores de scripts de vistas
  195. basados en la acción actual. El principal problema que se puede encontrar es
  196. si se tiene acciones que no generan scripts de vista y tampoco llevan
  197. o redireccionan, como <code>ViewRenderer</code> intentará generar
  198. un scrip de vista basado en el nombre de la acción.
  199. </para>
  200. <para>
  201. There are several strategies you can take to update your code. In
  202. the short term, you can globally disable the
  203. <code>ViewRenderer</code> in your front controller bootstrap prior
  204. to dispatching:
  205. </para>
  206. <programlisting role="php"><![CDATA[
  207. // Assuming $front is an instance of Zend_Controller_Front
  208. $front->setParam('noViewRenderer', true);
  209. ]]></programlisting>
  210. <para>
  211. However, this is not a good long term strategy, as it means most
  212. likely you'll be writing more code.
  213. </para>
  214. <para>
  215. When you're ready to start using the <code>ViewRenderer</code>
  216. functionality, there are several things to look for in your
  217. controller code. First, look at your action methods (the methods
  218. ending in 'Action'), and determine what each is doing. If none of
  219. the following is happening, you'll need to make changes:
  220. </para>
  221. <itemizedlist>
  222. <listitem><para>Calls to <code>$this-&gt;render()</code></para></listitem>
  223. <listitem><para>Calls to <code>$this-&gt;_forward()</code></para></listitem>
  224. <listitem><para>Calls to <code>$this-&gt;_redirect()</code></para></listitem>
  225. <listitem><para>Calls to the <code>Redirector</code> action helper</para></listitem>
  226. </itemizedlist>
  227. <para>
  228. The easiest change is to disable auto-rendering for that method:
  229. </para>
  230. <programlisting role="php"><![CDATA[
  231. $this->_helper->viewRenderer->setNoRender();
  232. ]]></programlisting>
  233. <para>
  234. If you find that none of your action methods are rendering,
  235. forwarding, or redirecting, you will likely want to put the above
  236. line in your <code>preDispatch()</code> or <code>init()</code>
  237. methods:
  238. </para>
  239. <programlisting role="php"><![CDATA[
  240. public function preDispatch()
  241. {
  242. // disable view script autorendering
  243. $this->_helper->viewRenderer->setNoRender()
  244. // .. do other things...
  245. }
  246. ]]></programlisting>
  247. <para>
  248. If you are calling <code>render()</code>, and you're using <link
  249. linkend="zend.controller.modular">the Conventional Modular
  250. directory structure</link>, you'll want to change your code to
  251. make use of autorendering:
  252. </para>
  253. <itemizedlist>
  254. <listitem>
  255. <para>
  256. If you're rendering multiple view scripts in a single
  257. action, you don't need to change a thing.
  258. </para>
  259. </listitem>
  260. <listitem>
  261. <para>
  262. If you're simply calling <code>render()</code> with no
  263. arguments, you can remove such lines.
  264. </para>
  265. </listitem>
  266. <listitem>
  267. <para>
  268. If you're calling <code>render()</code> with arguments, and
  269. not doing any processing afterwards or rendering multiple
  270. view scripts, you can change these calls to read
  271. <code>$this-&gt;_helper-&gt;viewRenderer()</code>.
  272. </para>
  273. </listitem>
  274. </itemizedlist>
  275. <para>
  276. If you're not using the conventional modular directory structure,
  277. there are a variety of methods for setting the view base path and
  278. script path specifications so that you can make use of the
  279. <code>ViewRenderer</code>. Please read the <link
  280. linkend="zend.controller.actionhelpers.viewrenderer">ViewRenderer
  281. documentation</link> for information on these methods.
  282. </para>
  283. <para>
  284. If you're using a view object from the registry, or customizing your
  285. view object, or using a different view implementation, you'll want
  286. to inject the <code>ViewRenderer</code> with this object. This can
  287. be done easily at any time.
  288. </para>
  289. <itemizedlist>
  290. <listitem>
  291. <para>
  292. Prior to dispatching a front controller instance:
  293. </para>
  294. <programlisting role="php"><![CDATA[
  295. // Assuming $view has already been defined
  296. $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
  297. Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
  298. ]]></programlisting>
  299. </listitem>
  300. <listitem>
  301. <para>
  302. Any time during the bootstrap process:
  303. </para>
  304. <programlisting role="php"><![CDATA[
  305. $viewRenderer =
  306. Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
  307. $viewRenderer->setView($view);
  308. ]]></programlisting>
  309. </listitem>
  310. </itemizedlist>
  311. <para>
  312. There are many ways to modify the <code>ViewRenderer</code>,
  313. including setting a different view script to render, specifying
  314. replacements for all replaceable elements of a view script path
  315. (including the suffix), choosing a response named segment to
  316. utilize, and more. If you aren't using the conventional modular
  317. directory structure, you can even associate different path
  318. specifications with the <code>ViewRenderer</code>.
  319. </para>
  320. <para>
  321. We encourage you to adapt your code to use the
  322. <code>ErrorHandler</code> and <code>ViewRenderer</code> as they are
  323. now core functionality.
  324. </para>
  325. </sect2>
  326. <sect2 id="zend.controller.migration.fromzeroninetwo">
  327. <title>Migrating from 0.9.2 to 0.9.3 or Newer</title>
  328. <para>
  329. 0.9.3 introduces <link
  330. linkend="zend.controller.actionhelpers">action helpers</link>.
  331. As part of this change, the following methods have been removed as
  332. they are now encapsulated in the <link
  333. linkend="zend.controller.actionhelpers.redirector">redirector
  334. action helper</link>:
  335. </para>
  336. <itemizedlist>
  337. <listitem>
  338. <para>
  339. <code>setRedirectCode()</code>; use
  340. <classname>Zend_Controller_Action_Helper_Redirector::setCode()</classname>.
  341. </para>
  342. </listitem>
  343. <listitem>
  344. <para>
  345. <code>setRedirectPrependBase()</code>; use
  346. <classname>Zend_Controller_Action_Helper_Redirector::setPrependBase()</classname>.
  347. </para>
  348. </listitem>
  349. <listitem>
  350. <para>
  351. <code>setRedirectExit()</code>; use
  352. <classname>Zend_Controller_Action_Helper_Redirector::setExit()</classname>.
  353. </para>
  354. </listitem>
  355. </itemizedlist>
  356. <para>
  357. Read the <link linkend="zend.controller.actionhelpers">action
  358. helpers documentation</link> for more information on how to
  359. retrieve and manipulate helper objects, and the <link
  360. linkend="zend.controller.actionhelpers.redirector">redirector
  361. helper documentation</link> for more information on setting
  362. redirect options (as well as alternate methods for redirecting).
  363. </para>
  364. </sect2>
  365. <sect2 id="zend.controller.migration.fromzerosix">
  366. <title>Migrating from 0.6.0 to 0.8.0 or Newer</title>
  367. <para>
  368. Per previous changes, the most basic usage of the MVC components
  369. remains the same:
  370. </para>
  371. <programlisting role="php"><![CDATA[
  372. Zend_Controller_Front::run('/path/to/controllers');
  373. ]]></programlisting>
  374. <para>
  375. However, the directory structure underwent an overhaul, several
  376. components were removed, and several others either renamed or added.
  377. Changes include:
  378. </para>
  379. <itemizedlist>
  380. <listitem>
  381. <para>
  382. <classname>Zend_Controller_Router</classname> was removed in favor of
  383. the rewrite router.
  384. </para>
  385. </listitem>
  386. <listitem>
  387. <para>
  388. <classname>Zend_Controller_RewriteRouter</classname> was renamed to
  389. <classname>Zend_Controller_Router_Rewrite</classname>, and promoted to
  390. the standard router shipped with the framework;
  391. <classname>Zend_Controller_Front</classname> will use it by default if
  392. no other router is supplied.
  393. </para>
  394. </listitem>
  395. <listitem>
  396. <para>
  397. A new route class for use with the rewrite router was
  398. introduced,
  399. <classname>Zend_Controller_Router_Route_Module</classname>; it covers
  400. the default route used by the MVC, and has support for <link
  401. linkend="zend.controller.modular">controller
  402. modules</link>.
  403. </para>
  404. </listitem>
  405. <listitem>
  406. <para>
  407. <classname>Zend_Controller_Router_StaticRoute</classname> was renamed
  408. to <classname>Zend_Controller_Router_Route_Static</classname>.
  409. </para>
  410. </listitem>
  411. <listitem>
  412. <para>
  413. <classname>Zend_Controller_Dispatcher</classname> was renamed
  414. <classname>Zend_Controller_Dispatcher_Standard</classname>.
  415. </para>
  416. </listitem>
  417. <listitem>
  418. <para>
  419. <classname>Zend_Controller_Action::_forward()</classname>'s arguments
  420. have changed. The signature is now:
  421. </para>
  422. <programlisting role="php"><![CDATA[
  423. final protected function _forward($action,
  424. $controller = null,
  425. $module = null,
  426. array $params = null);
  427. ]]></programlisting>
  428. <para>
  429. <code>$action</code> is always required; if no controller is
  430. specified, an action in the current controller is assumed.
  431. <code>$module</code> is always ignored unless
  432. <code>$controller</code> is specified. Finally, any
  433. <code>$params</code> provided will be appended to the
  434. request object. If you do not require the controller or
  435. module, but still need to pass parameters, simply specify
  436. null for those values.
  437. </para>
  438. </listitem>
  439. </itemizedlist>
  440. </sect2>
  441. <sect2 id="zend.controller.migration.fromzerotwo">
  442. <title>Migrating from 0.2.0 or before to 0.6.0</title>
  443. <para>
  444. The most basic usage of the MVC components has not changed; you can
  445. still do each of the following:
  446. </para>
  447. <programlisting role="php"><![CDATA[
  448. Zend_Controller_Front::run('/path/to/controllers');
  449. ]]></programlisting>
  450. <programlisting role="php"><![CDATA[
  451. /* -- create a router -- */
  452. $router = new Zend_Controller_RewriteRouter();
  453. $router->addRoute('user',
  454. 'user/:username',
  455. array('controller' => 'user', 'action' => 'info')
  456. );
  457. /* -- set it in a controller -- */
  458. $ctrl = Zend_Controller_Front::getInstance();
  459. $ctrl->setRouter($router);
  460. /* -- set controller directory and dispatch -- */
  461. $ctrl->setControllerDirectory('/path/to/controllers');
  462. $ctrl->dispatch();
  463. ]]></programlisting>
  464. <para>
  465. We encourage use of the Response object to aggregate content and
  466. headers. This will allow for more flexible output format switching
  467. (for instance, JSON or XML instead of XHTML) in your applications.
  468. By default, <code>dispatch()</code> will render the response, sending both
  469. headers and rendering any content. You may also have the front
  470. controller return the response using <code>returnResponse()</code>,
  471. and then render the response using your own logic. A future version
  472. of the front controller may enforce use of the response object via
  473. output buffering.
  474. </para>
  475. <para>
  476. There are many additional features that extend the existing API,
  477. and these are noted in the documentation.
  478. </para>
  479. <para>
  480. The main changes you will need to be aware of will be found when
  481. subclassing the various components. Key amongst these are:
  482. </para>
  483. <itemizedlist>
  484. <listitem>
  485. <para>
  486. <classname>Zend_Controller_Front::dispatch()</classname> by default
  487. traps exceptions in the response object, and does not render
  488. them, in order to prevent sensitive system information from
  489. being rendered. You can override this in several ways:
  490. </para>
  491. <itemizedlist>
  492. <listitem>
  493. <para>
  494. Set <code>throwExceptions()</code> in the front
  495. controller:
  496. </para>
  497. <programlisting role="php"><![CDATA[
  498. $front->throwExceptions(true);
  499. ]]></programlisting>
  500. </listitem>
  501. <listitem>
  502. <para>
  503. Set <code>renderExceptions()</code> in the response
  504. object:
  505. </para>
  506. <programlisting role="php"><![CDATA[
  507. $response->renderExceptions(true);
  508. $front->setResponse($response);
  509. $front->dispatch();
  510. // or:
  511. $front->returnResponse(true);
  512. $response = $front->dispatch();
  513. $response->renderExceptions(true);
  514. echo $response;
  515. ]]></programlisting>
  516. </listitem>
  517. </itemizedlist>
  518. </listitem>
  519. <listitem><para>
  520. <classname>Zend_Controller_Dispatcher_Interface::dispatch()</classname>
  521. now accepts and returns a <xref linkend="zend.controller.request" />
  522. object instead of a dispatcher token.
  523. </para></listitem>
  524. <listitem><para>
  525. <classname>Zend_Controller_Router_Interface::route()</classname>
  526. now accepts and returns a <xref linkend="zend.controller.request" />
  527. object instead of a dispatcher token.
  528. </para></listitem>
  529. <listitem>
  530. <para><classname>Zend_Controller_Action</classname> changes include:</para>
  531. <itemizedlist>
  532. <listitem><para>
  533. The constructor now accepts exactly three arguments,
  534. <classname>Zend_Controller_Request_Abstract $request</classname>,
  535. <classname>Zend_Controller_Response_Abstract $response</classname>,
  536. and <code>array $params (optional)</code>.
  537. <classname>Zend_Controller_Action::__construct()</classname> uses
  538. these to set the request, response, and invokeArgs
  539. properties of the object, and if overriding the
  540. constructor, you should do so as well. Better yet, use
  541. the <code>init()</code> method to do any instance
  542. configuration, as this method is called as the final
  543. action of the constructor.
  544. </para></listitem>
  545. <listitem><para>
  546. <code>run()</code> is no longer defined as final, but is
  547. also no longer used by the front controller; its sole
  548. purpose is for using the class as a page controller. It
  549. now takes two optional arguments, a
  550. <classname>Zend_Controller_Request_Abstract $request</classname>
  551. and a <classname>Zend_Controller_Response_Abstract $response</classname>.
  552. </para></listitem>
  553. <listitem><para>
  554. <code>indexAction()</code> no longer needs to be
  555. defined, but is encouraged as the default action. This
  556. allows using the RewriteRouter and action controllers to
  557. specify different default action methods.
  558. </para></listitem>
  559. <listitem><para>
  560. <code>__call()</code> should be overridden to handle any
  561. undefined actions automatically.
  562. </para></listitem>
  563. <listitem><para>
  564. <code>_redirect()</code> now takes an optional second
  565. argument, the HTTP code to return with the redirect, and
  566. an optional third argument, <code>$prependBase</code>,
  567. that can indicate that the base URL registered with the
  568. request object should be prepended to the url specified.
  569. </para></listitem>
  570. <listitem>
  571. <para>
  572. The <code>_action</code> property is no longer set.
  573. This property was a <classname>Zend_Controller_Dispatcher_Token</classname>,
  574. which no longer exists in the current incarnation.
  575. The sole purpose of the token was to provide
  576. information about the requested controller, action,
  577. and URL parameters. This information is now
  578. available in the request object, and can be accessed
  579. as follows:
  580. </para>
  581. <programlisting role="php"><![CDATA[
  582. // Retrieve the requested controller name
  583. // Access used to be via: $this->_action->getControllerName().
  584. // The example below uses getRequest(), though you may also directly
  585. // access the $_request property; using getRequest() is recommended as
  586. // a parent class may override access to the request object.
  587. $controller = $this->getRequest()->getControllerName();
  588. // Retrieve the requested action name
  589. // Access used to be via: $this->_action->getActionName().
  590. $action = $this->getRequest()->getActionName();
  591. // Retrieve the request parameters
  592. // This hasn't changed; the _getParams() and _getParam() methods simply
  593. // proxy to the request object now.
  594. $params = $this->_getParams();
  595. // request 'foo' parameter, using 'default' as default value if not found
  596. $foo = $this->_getParam('foo', 'default');
  597. ]]></programlisting>
  598. </listitem>
  599. <listitem>
  600. <para>
  601. <code>noRouteAction()</code> has been removed. The
  602. appropriate way to handle non-existent action
  603. methods should you wish to route them to a default
  604. action is using <code>__call()</code>:
  605. </para>
  606. <programlisting role="php"><![CDATA[
  607. public function __call($method, $args)
  608. {
  609. // If an unmatched 'Action' method was requested, pass on to the
  610. // default action method:
  611. if ('Action' == substr($method, -6)) {
  612. return $this->defaultAction();
  613. }
  614. throw new Zend_Controller_Exception('Invalid method called');
  615. }
  616. ]]></programlisting>
  617. </listitem>
  618. </itemizedlist>
  619. </listitem>
  620. <listitem><para>
  621. <classname>Zend_Controller_RewriteRouter::setRewriteBase()</classname> has
  622. been removed. Use <classname>Zend_Controller_Front::setBaseUrl()</classname>
  623. instead (or <classname>Zend_Controller_Request_Http::setBaseUrl()</classname>, if using
  624. that request class).
  625. </para></listitem>
  626. <listitem><para>
  627. <classname>Zend_Controller_Plugin_Interface</classname> was replaced
  628. by <classname>Zend_Controller_Plugin_Abstract</classname>. All methods now
  629. accept and return a <xref linkend="zend.controller.request" />
  630. object instead of a dispatcher token.
  631. </para></listitem>
  632. </itemizedlist>
  633. </sect2>
  634. </sect1>
  635. <!--
  636. vim:se ts=4 sw=4 et:
  637. -->