Zend_Controller-Migration.xml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.controller.migration">
  4. <title>Migrating from Previous Versions</title>
  5. <para>
  6. The API of the MVC components has changed over time. If you started
  7. using Zend Framework in an early version, follow the guidelines below to
  8. migrate your scripts to use the new architecture.
  9. </para>
  10. <sect2 id="zend.controller.migration.fromoneseventooneeight">
  11. <title>Migrating from 1.7.x to 1.8.0 or newer</title>
  12. <sect3 id="zend.controller.migration.fromoneseventooneeight.router">
  13. <title>Standard Route Changes</title>
  14. <para>
  15. As translated segments were introduced into the new standard
  16. route, the <code>@</code> character is now a special character
  17. in the beginning of a route segment. To be able to use it in a
  18. static segment, you must escape it by prefixing it with second
  19. <code>@</code> character. The same rule now applies for the
  20. <code>:</code> character.
  21. </para>
  22. </sect3>
  23. </sect2>
  24. <sect2 id="zend.controller.migration.fromonesixtooneseven">
  25. <title>Migrating from 1.6.x to 1.7.0 or newer</title>
  26. <sect3 id="zend.controller.migration.fromonesixtooneseven.dispatcher">
  27. <title>Dispatcher Interface Changes</title>
  28. <para>
  29. Users brought to our attention the fact that
  30. <classname>Zend_Controller_Action_Helper_ViewRenderer</classname> were
  31. using a method of the dispatcher abstract class that was not in
  32. the dispatcher interface. We have now added the following method to
  33. ensure that custom dispatchers will continue to work with the
  34. shipped implementations:
  35. </para>
  36. <itemizedlist>
  37. <listitem><para>
  38. <code>formatModuleName()</code>: should be used to take a raw
  39. controller name, such as one that would be packaged inside a request
  40. object, and reformat it to a proper class name that a class extending
  41. <classname>Zend_Controller_Action</classname> would use
  42. </para></listitem>
  43. </itemizedlist>
  44. </sect3>
  45. </sect2>
  46. <sect2 id="zend.controller.migration.fromoneohtoonesix">
  47. <title>Migrating from 1.5.x to 1.6.0 or Newer</title>
  48. <sect3 id="zend.controller.migration.fromoneohtoonesix.dispatcher">
  49. <title>Dispatcher Interface Changes</title>
  50. <para>
  51. Users brought to our attention the fact that
  52. <classname>Zend_Controller_Front</classname> and
  53. <classname>Zend_Controller_Router_Route_Module</classname> were each
  54. using methods of the dispatcher that were not in the dispatcher
  55. interface. We have now added the following three methods to
  56. ensure that custom dispatchers will continue to work with the
  57. shipped implementations:
  58. </para>
  59. <itemizedlist>
  60. <listitem><para>
  61. <code>getDefaultModule()</code>: should return the name of
  62. the default module.
  63. </para></listitem>
  64. <listitem><para>
  65. <code>getDefaultControllerName()</code>: should return the
  66. name of the default controller.
  67. </para></listitem>
  68. <listitem><para>
  69. <code>getDefaultAction()</code>: should return the
  70. name of the default action.
  71. </para></listitem>
  72. </itemizedlist>
  73. </sect3>
  74. </sect2>
  75. <sect2 id="zend.controller.migration.fromoneohtoonefive">
  76. <title>Migrating from 1.0.x to 1.5.0 or Newer</title>
  77. <para>
  78. Though most basic functionality remains the same, and all documented
  79. functionality remains the same, there is one particular
  80. <emphasis>undocumented</emphasis> "feature" that has changed.
  81. </para>
  82. <para>
  83. When writing URLs, the documented way to write camelCased action
  84. names is to use a word separator; these are '.' or '-' by default,
  85. but may be configured in the dispatcher. The dispatcher internally
  86. lowercases the action name, and uses these word separators to
  87. re-assemble the action method using camelCasing. However, because PHP
  88. functions are not case sensitive, you <emphasis>could</emphasis>
  89. still write URLs using camelCasing, and the dispatcher would resolve
  90. these to the same location. For example, 'camel-cased' would become
  91. 'camelCasedAction' by the dispatcher, whereas 'camelCased' would
  92. become 'camelcasedAction'; however, due to the case insensitivity of
  93. PHP, both will execute the same method.
  94. </para>
  95. <para>
  96. This causes issues with the ViewRenderer when resolving view
  97. scripts. The canonical, documented way is that all word separators
  98. are converted to dashes, and the words lowercased. This creates
  99. a semantic tie between the actions and view scripts, and the
  100. normalization ensures that the scripts can be found. However, if the
  101. action 'camelCased' is called and actually resolves, the word
  102. separator is no longer present, and the ViewRenderer attempts to
  103. resolve to a different location -- 'camelcased.phtml' instead of
  104. 'camel-cased.phtml'.
  105. </para>
  106. <para>
  107. Some developers relied on this "feature", which was never intended.
  108. Several changes in the 1.5.0 tree, however, made it so that the
  109. ViewRenderer no longer resolves these paths; the semantic tie is now
  110. enforced. First among these, the dispatcher now enforces case
  111. sensitivity in action names. What this means is that referring to
  112. your actions on the url using camelCasing will no longer resolve to
  113. the same method as using word separators (i.e., 'camel-casing').
  114. This leads to the ViewRenderer now only honoring the word-separated
  115. actions when resolving view scripts.
  116. </para>
  117. <para>
  118. If you find that you were relying on this "feature", you have several
  119. options:
  120. </para>
  121. <itemizedlist>
  122. <listitem><para>
  123. Best option: rename your view scripts. Pros: forward
  124. compatibility. Cons: if you have many view scripts that
  125. relied on the former, unintended behavior, you will have a
  126. lot of renaming to do.
  127. </para></listitem>
  128. <listitem>
  129. <para>
  130. Second best option: The ViewRenderer now delegates view
  131. script resolution to <classname>Zend_Filter_Inflector</classname>; you
  132. can modify the rules of the inflector to no longer separate
  133. the words of an action with a dash:
  134. </para>
  135. <programlisting language="php"><![CDATA[
  136. $viewRenderer =
  137. Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
  138. $inflector = $viewRenderer->getInflector();
  139. $inflector->setFilterRule(':action', array(
  140. new Zend_Filter_PregReplace(
  141. '#[^a-z0-9' . preg_quote(DIRECTORY_SEPARATOR, '#') . ']+#i',
  142. ''
  143. ),
  144. 'StringToLower'
  145. ));
  146. ]]></programlisting>
  147. <para>
  148. The above code will modify the inflector to no longer
  149. separate the words with dash; you may also want to remove
  150. the 'StringToLower' filter if you <emphasis>do</emphasis>
  151. want the actual view script names camelCased as well.
  152. </para>
  153. <para>
  154. If renaming your view scripts would be too tedious or time
  155. consuming, this is your best option until you can find the
  156. time to do so.
  157. </para>
  158. </listitem>
  159. <listitem>
  160. <para>
  161. Least desirable option: You can force the dispatcher to
  162. dispatch camelCased action names with a new front controller
  163. flag, 'useCaseSensitiveActions':
  164. </para>
  165. <programlisting language="php"><![CDATA[
  166. $front->setParam('useCaseSensitiveActions', true);
  167. ]]></programlisting>
  168. <para>
  169. This will allow you to use camelCasing on the url and still
  170. have it resolve to the same action as when you use word
  171. separators. However, this will mean that the original issues
  172. will cascade on through; you will likely need to use the
  173. second option above in addition to this for things to work
  174. at all reliably.
  175. </para>
  176. <para>
  177. Note, also, that usage of this flag will raise a notice that
  178. this usage is deprecated.
  179. </para>
  180. </listitem>
  181. </itemizedlist>
  182. </sect2>
  183. <sect2 id="zend.controller.migration.fromzeroninethree">
  184. <title>Migrating from 0.9.3 to 1.0.0RC1 or Newer</title>
  185. <para>
  186. The principal changes introduced in 1.0.0RC1 are the introduction of
  187. and default enabling of the
  188. <link
  189. linkend="zend.controller.plugins.standard.errorhandler">ErrorHandler</link>
  190. plugin and the <link
  191. linkend="zend.controller.actionhelpers.viewrenderer">ViewRenderer</link>
  192. action helper. Please read the documentation to each thoroughly to
  193. see how they work and what effect they may have on your
  194. applications.
  195. </para>
  196. <para>
  197. The <code>ErrorHandler</code> plugin runs during
  198. <code>postDispatch()</code> checking for exceptions, and forwarding
  199. to a specified error handler controller. You should include such a
  200. controller in your application. You may disable it by setting the
  201. front controller parameter <code>noErrorHandler</code>:
  202. </para>
  203. <programlisting language="php"><![CDATA[
  204. $front->setParam('noErrorHandler', true);
  205. ]]></programlisting>
  206. <para>
  207. The <code>ViewRenderer</code> action helper automates view injection
  208. into action controllers as well as autorendering of view scripts
  209. based on the current action. The primary issue you may encounter is
  210. if you have actions that do not render view scripts and neither
  211. forward or redirect, as the <code>ViewRenderer</code> will attempt
  212. to render a view script based on the action name.
  213. </para>
  214. <para>
  215. There are several strategies you can take to update your code. In
  216. the short term, you can globally disable the
  217. <code>ViewRenderer</code> in your front controller bootstrap prior
  218. to dispatching:
  219. </para>
  220. <programlisting language="php"><![CDATA[
  221. // Assuming $front is an instance of Zend_Controller_Front
  222. $front->setParam('noViewRenderer', true);
  223. ]]></programlisting>
  224. <para>
  225. However, this is not a good long term strategy, as it means most
  226. likely you'll be writing more code.
  227. </para>
  228. <para>
  229. When you're ready to start using the <code>ViewRenderer</code>
  230. functionality, there are several things to look for in your
  231. controller code. First, look at your action methods (the methods
  232. ending in 'Action'), and determine what each is doing. If none of
  233. the following is happening, you'll need to make changes:
  234. </para>
  235. <itemizedlist>
  236. <listitem><para>Calls to <code>$this-&gt;render()</code></para></listitem>
  237. <listitem><para>Calls to <code>$this-&gt;_forward()</code></para></listitem>
  238. <listitem><para>Calls to <code>$this-&gt;_redirect()</code></para></listitem>
  239. <listitem><para>Calls to the <code>Redirector</code> action helper</para></listitem>
  240. </itemizedlist>
  241. <para>
  242. The easiest change is to disable auto-rendering for that method:
  243. </para>
  244. <programlisting language="php"><![CDATA[
  245. $this->_helper->viewRenderer->setNoRender();
  246. ]]></programlisting>
  247. <para>
  248. If you find that none of your action methods are rendering,
  249. forwarding, or redirecting, you will likely want to put the above
  250. line in your <code>preDispatch()</code> or <code>init()</code>
  251. methods:
  252. </para>
  253. <programlisting language="php"><![CDATA[
  254. public function preDispatch()
  255. {
  256. // disable view script autorendering
  257. $this->_helper->viewRenderer->setNoRender()
  258. // .. do other things...
  259. }
  260. ]]></programlisting>
  261. <para>
  262. If you are calling <code>render()</code>, and you're using <link
  263. linkend="zend.controller.modular">the Conventional Modular
  264. directory structure</link>, you'll want to change your code to
  265. make use of autorendering:
  266. </para>
  267. <itemizedlist>
  268. <listitem>
  269. <para>
  270. If you're rendering multiple view scripts in a single
  271. action, you don't need to change a thing.
  272. </para>
  273. </listitem>
  274. <listitem>
  275. <para>
  276. If you're simply calling <code>render()</code> with no
  277. arguments, you can remove such lines.
  278. </para>
  279. </listitem>
  280. <listitem>
  281. <para>
  282. If you're calling <code>render()</code> with arguments, and
  283. not doing any processing afterwards or rendering multiple
  284. view scripts, you can change these calls to read
  285. <code>$this-&gt;_helper-&gt;viewRenderer()</code>.
  286. </para>
  287. </listitem>
  288. </itemizedlist>
  289. <para>
  290. If you're not using the conventional modular directory structure,
  291. there are a variety of methods for setting the view base path and
  292. script path specifications so that you can make use of the
  293. <code>ViewRenderer</code>. Please read the <link
  294. linkend="zend.controller.actionhelpers.viewrenderer">ViewRenderer
  295. documentation</link> for information on these methods.
  296. </para>
  297. <para>
  298. If you're using a view object from the registry, or customizing your
  299. view object, or using a different view implementation, you'll want
  300. to inject the <code>ViewRenderer</code> with this object. This can
  301. be done easily at any time.
  302. </para>
  303. <itemizedlist>
  304. <listitem>
  305. <para>
  306. Prior to dispatching a front controller instance:
  307. </para>
  308. <programlisting language="php"><![CDATA[
  309. // Assuming $view has already been defined
  310. $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
  311. Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
  312. ]]></programlisting>
  313. </listitem>
  314. <listitem>
  315. <para>
  316. Any time during the bootstrap process:
  317. </para>
  318. <programlisting language="php"><![CDATA[
  319. $viewRenderer =
  320. Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
  321. $viewRenderer->setView($view);
  322. ]]></programlisting>
  323. </listitem>
  324. </itemizedlist>
  325. <para>
  326. There are many ways to modify the <code>ViewRenderer</code>,
  327. including setting a different view script to render, specifying
  328. replacements for all replaceable elements of a view script path
  329. (including the suffix), choosing a response named segment to
  330. utilize, and more. If you aren't using the conventional modular
  331. directory structure, you can even associate different path
  332. specifications with the <code>ViewRenderer</code>.
  333. </para>
  334. <para>
  335. We encourage you to adapt your code to use the
  336. <code>ErrorHandler</code> and <code>ViewRenderer</code> as they are
  337. now core functionality.
  338. </para>
  339. </sect2>
  340. <sect2 id="zend.controller.migration.fromzeroninetwo">
  341. <title>Migrating from 0.9.2 to 0.9.3 or Newer</title>
  342. <para>
  343. 0.9.3 introduces <link
  344. linkend="zend.controller.actionhelpers">action helpers</link>.
  345. As part of this change, the following methods have been removed as
  346. they are now encapsulated in the <link
  347. linkend="zend.controller.actionhelpers.redirector">redirector
  348. action helper</link>:
  349. </para>
  350. <itemizedlist>
  351. <listitem>
  352. <para>
  353. <code>setRedirectCode()</code>; use
  354. <classname>Zend_Controller_Action_Helper_Redirector::setCode()</classname>.
  355. </para>
  356. </listitem>
  357. <listitem>
  358. <para>
  359. <code>setRedirectPrependBase()</code>; use
  360. <classname>Zend_Controller_Action_Helper_Redirector::setPrependBase()</classname>.
  361. </para>
  362. </listitem>
  363. <listitem>
  364. <para>
  365. <code>setRedirectExit()</code>; use
  366. <classname>Zend_Controller_Action_Helper_Redirector::setExit()</classname>.
  367. </para>
  368. </listitem>
  369. </itemizedlist>
  370. <para>
  371. Read the <link linkend="zend.controller.actionhelpers">action
  372. helpers documentation</link> for more information on how to
  373. retrieve and manipulate helper objects, and the <link
  374. linkend="zend.controller.actionhelpers.redirector">redirector
  375. helper documentation</link> for more information on setting
  376. redirect options (as well as alternate methods for redirecting).
  377. </para>
  378. </sect2>
  379. <sect2 id="zend.controller.migration.fromzerosix">
  380. <title>Migrating from 0.6.0 to 0.8.0 or Newer</title>
  381. <para>
  382. Per previous changes, the most basic usage of the MVC components
  383. remains the same:
  384. </para>
  385. <programlisting language="php"><![CDATA[
  386. Zend_Controller_Front::run('/path/to/controllers');
  387. ]]></programlisting>
  388. <para>
  389. However, the directory structure underwent an overhaul, several
  390. components were removed, and several others either renamed or added.
  391. Changes include:
  392. </para>
  393. <itemizedlist>
  394. <listitem>
  395. <para>
  396. <classname>Zend_Controller_Router</classname> was removed in favor of
  397. the rewrite router.
  398. </para>
  399. </listitem>
  400. <listitem>
  401. <para>
  402. <classname>Zend_Controller_RewriteRouter</classname> was renamed to
  403. <classname>Zend_Controller_Router_Rewrite</classname>, and promoted to
  404. the standard router shipped with the framework;
  405. <classname>Zend_Controller_Front</classname> will use it by default if
  406. no other router is supplied.
  407. </para>
  408. </listitem>
  409. <listitem>
  410. <para>
  411. A new route class for use with the rewrite router was
  412. introduced,
  413. <classname>Zend_Controller_Router_Route_Module</classname>; it covers
  414. the default route used by the MVC, and has support for <link
  415. linkend="zend.controller.modular">controller
  416. modules</link>.
  417. </para>
  418. </listitem>
  419. <listitem>
  420. <para>
  421. <classname>Zend_Controller_Router_StaticRoute</classname> was renamed
  422. to <classname>Zend_Controller_Router_Route_Static</classname>.
  423. </para>
  424. </listitem>
  425. <listitem>
  426. <para>
  427. <classname>Zend_Controller_Dispatcher</classname> was renamed
  428. <classname>Zend_Controller_Dispatcher_Standard</classname>.
  429. </para>
  430. </listitem>
  431. <listitem>
  432. <para>
  433. <classname>Zend_Controller_Action::_forward()</classname>'s arguments
  434. have changed. The signature is now:
  435. </para>
  436. <programlisting language="php"><![CDATA[
  437. final protected function _forward($action,
  438. $controller = null,
  439. $module = null,
  440. array $params = null);
  441. ]]></programlisting>
  442. <para>
  443. <varname>$action</varname> is always required; if no controller is
  444. specified, an action in the current controller is assumed.
  445. <varname>$module</varname> is always ignored unless
  446. <varname>$controller</varname> is specified. Finally, any
  447. <varname>$params</varname> provided will be appended to the
  448. request object. If you do not require the controller or
  449. module, but still need to pass parameters, simply specify
  450. null for those values.
  451. </para>
  452. </listitem>
  453. </itemizedlist>
  454. </sect2>
  455. <sect2 id="zend.controller.migration.fromzerotwo">
  456. <title>Migrating from 0.2.0 or before to 0.6.0</title>
  457. <para>
  458. The most basic usage of the MVC components has not changed; you can
  459. still do each of the following:
  460. </para>
  461. <programlisting language="php"><![CDATA[
  462. Zend_Controller_Front::run('/path/to/controllers');
  463. ]]></programlisting>
  464. <programlisting language="php"><![CDATA[
  465. /* -- create a router -- */
  466. $router = new Zend_Controller_RewriteRouter();
  467. $router->addRoute('user',
  468. 'user/:username',
  469. array('controller' => 'user', 'action' => 'info')
  470. );
  471. /* -- set it in a controller -- */
  472. $ctrl = Zend_Controller_Front::getInstance();
  473. $ctrl->setRouter($router);
  474. /* -- set controller directory and dispatch -- */
  475. $ctrl->setControllerDirectory('/path/to/controllers');
  476. $ctrl->dispatch();
  477. ]]></programlisting>
  478. <para>
  479. We encourage use of the Response object to aggregate content and
  480. headers. This will allow for more flexible output format switching
  481. (for instance, JSON or XML instead of XHTML) in your applications.
  482. By default, <code>dispatch()</code> will render the response, sending both
  483. headers and rendering any content. You may also have the front
  484. controller return the response using <code>returnResponse()</code>,
  485. and then render the response using your own logic. A future version
  486. of the front controller may enforce use of the response object via
  487. output buffering.
  488. </para>
  489. <para>
  490. There are many additional features that extend the existing API,
  491. and these are noted in the documentation.
  492. </para>
  493. <para>
  494. The main changes you will need to be aware of will be found when
  495. subclassing the various components. Key amongst these are:
  496. </para>
  497. <itemizedlist>
  498. <listitem>
  499. <para>
  500. <classname>Zend_Controller_Front::dispatch()</classname> by default
  501. traps exceptions in the response object, and does not render
  502. them, in order to prevent sensitive system information from
  503. being rendered. You can override this in several ways:
  504. </para>
  505. <itemizedlist>
  506. <listitem>
  507. <para>
  508. Set <code>throwExceptions()</code> in the front
  509. controller:
  510. </para>
  511. <programlisting language="php"><![CDATA[
  512. $front->throwExceptions(true);
  513. ]]></programlisting>
  514. </listitem>
  515. <listitem>
  516. <para>
  517. Set <code>renderExceptions()</code> in the response
  518. object:
  519. </para>
  520. <programlisting language="php"><![CDATA[
  521. $response->renderExceptions(true);
  522. $front->setResponse($response);
  523. $front->dispatch();
  524. // or:
  525. $front->returnResponse(true);
  526. $response = $front->dispatch();
  527. $response->renderExceptions(true);
  528. echo $response;
  529. ]]></programlisting>
  530. </listitem>
  531. </itemizedlist>
  532. </listitem>
  533. <listitem><para>
  534. <classname>Zend_Controller_Dispatcher_Interface::dispatch()</classname>
  535. now accepts and returns a <xref linkend="zend.controller.request" />
  536. object instead of a dispatcher token.
  537. </para></listitem>
  538. <listitem><para>
  539. <classname>Zend_Controller_Router_Interface::route()</classname>
  540. now accepts and returns a <xref linkend="zend.controller.request" />
  541. object instead of a dispatcher token.
  542. </para></listitem>
  543. <listitem>
  544. <para><classname>Zend_Controller_Action</classname> changes include:</para>
  545. <itemizedlist>
  546. <listitem><para>
  547. The constructor now accepts exactly three arguments,
  548. <classname>Zend_Controller_Request_Abstract $request</classname>,
  549. <classname>Zend_Controller_Response_Abstract $response</classname>,
  550. and <code>array $params (optional)</code>.
  551. <classname>Zend_Controller_Action::__construct()</classname> uses
  552. these to set the request, response, and invokeArgs
  553. properties of the object, and if overriding the
  554. constructor, you should do so as well. Better yet, use
  555. the <code>init()</code> method to do any instance
  556. configuration, as this method is called as the final
  557. action of the constructor.
  558. </para></listitem>
  559. <listitem><para>
  560. <code>run()</code> is no longer defined as final, but is
  561. also no longer used by the front controller; its sole
  562. purpose is for using the class as a page controller. It
  563. now takes two optional arguments, a
  564. <classname>Zend_Controller_Request_Abstract $request</classname>
  565. and a <classname>Zend_Controller_Response_Abstract $response</classname>.
  566. </para></listitem>
  567. <listitem><para>
  568. <code>indexAction()</code> no longer needs to be
  569. defined, but is encouraged as the default action. This
  570. allows using the RewriteRouter and action controllers to
  571. specify different default action methods.
  572. </para></listitem>
  573. <listitem><para>
  574. <code>__call()</code> should be overridden to handle any
  575. undefined actions automatically.
  576. </para></listitem>
  577. <listitem><para>
  578. <code>_redirect()</code> now takes an optional second
  579. argument, the HTTP code to return with the redirect, and
  580. an optional third argument, <varname>$prependBase</varname>,
  581. that can indicate that the base URL registered with the
  582. request object should be prepended to the url specified.
  583. </para></listitem>
  584. <listitem>
  585. <para>
  586. The <code>_action</code> property is no longer set. This property was a
  587. <classname>Zend_Controller_Dispatcher_Token</classname>,
  588. which no longer exists in the current incarnation.
  589. The sole purpose of the token was to provide
  590. information about the requested controller, action,
  591. and URL parameters. This information is now
  592. available in the request object, and can be accessed
  593. as follows:
  594. </para>
  595. <programlisting language="php"><![CDATA[
  596. // Retrieve the requested controller name
  597. // Access used to be via: $this->_action->getControllerName().
  598. // The example below uses getRequest(), though you may also directly
  599. // access the $_request property; using getRequest() is recommended as
  600. // a parent class may override access to the request object.
  601. $controller = $this->getRequest()->getControllerName();
  602. // Retrieve the requested action name
  603. // Access used to be via: $this->_action->getActionName().
  604. $action = $this->getRequest()->getActionName();
  605. // Retrieve the request parameters
  606. // This hasn't changed; the _getParams() and _getParam() methods simply
  607. // proxy to the request object now.
  608. $params = $this->_getParams();
  609. // request 'foo' parameter, using 'default' as default value if not found
  610. $foo = $this->_getParam('foo', 'default');
  611. ]]></programlisting>
  612. </listitem>
  613. <listitem>
  614. <para>
  615. <code>noRouteAction()</code> has been removed. The
  616. appropriate way to handle non-existent action
  617. methods should you wish to route them to a default
  618. action is using <code>__call()</code>:
  619. </para>
  620. <programlisting language="php"><![CDATA[
  621. public function __call($method, $args)
  622. {
  623. // If an unmatched 'Action' method was requested, pass on to the
  624. // default action method:
  625. if ('Action' == substr($method, -6)) {
  626. return $this->defaultAction();
  627. }
  628. throw new Zend_Controller_Exception('Invalid method called');
  629. }
  630. ]]></programlisting>
  631. </listitem>
  632. </itemizedlist>
  633. </listitem>
  634. <listitem><para>
  635. <classname>Zend_Controller_RewriteRouter::setRewriteBase()</classname> has
  636. been removed. Use <classname>Zend_Controller_Front::setBaseUrl()</classname>
  637. instead (or <classname>Zend_Controller_Request_Http::setBaseUrl()</classname>, if
  638. using that request class).
  639. </para></listitem>
  640. <listitem><para>
  641. <classname>Zend_Controller_Plugin_Interface</classname> was replaced
  642. by <classname>Zend_Controller_Plugin_Abstract</classname>. All methods now
  643. accept and return a <xref linkend="zend.controller.request" />
  644. object instead of a dispatcher token.
  645. </para></listitem>
  646. </itemizedlist>
  647. </sect2>
  648. </sect1>
  649. <!--
  650. vim:se ts=4 sw=4 et:
  651. -->