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>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.fromonesixtooneseven">
  11. <title>Migrating from 1.6.x to 1.7.0 or newer</title>
  12. <sect3 id="zend.controller.migration.fromonesixtooneseven.dispatcher">
  13. <title>Dispatcher Interface Changes</title>
  14. <para>
  15. Users brought to our attention the fact that
  16. <classname>Zend_Controller_Action_Helper_ViewRenderer</classname> were
  17. using a method of the dispatcher abstract class that was not in
  18. the dispatcher interface. We have now added the following method to
  19. ensure that custom dispatchers will continue to work with the
  20. shipped implementations:
  21. </para>
  22. <itemizedlist>
  23. <listitem><para>
  24. <code>formatModuleName()</code>: should be used to take a raw
  25. controller name, such as one that would be packaged inside a request
  26. object, and reformat it to a proper class name that a class extending
  27. <classname>Zend_Controller_Action</classname> would use
  28. </para></listitem>
  29. </itemizedlist>
  30. </sect3>
  31. </sect2>
  32. <sect2 id="zend.controller.migration.fromoneohtoonesix">
  33. <title>Migrating from 1.5.x to 1.6.0 or Newer</title>
  34. <sect3 id="zend.controller.migration.fromoneohtoonesix.dispatcher">
  35. <title>Dispatcher Interface Changes</title>
  36. <para>
  37. Users brought to our attention the fact that
  38. <classname>Zend_Controller_Front</classname> and
  39. <classname>Zend_Controller_Router_Route_Module</classname> were each
  40. using methods of the dispatcher that were not in the dispatcher
  41. interface. We have now added the following three methods to
  42. ensure that custom dispatchers will continue to work with the
  43. shipped implementations:
  44. </para>
  45. <itemizedlist>
  46. <listitem><para>
  47. <code>getDefaultModule()</code>: should return the name of
  48. the default module.
  49. </para></listitem>
  50. <listitem><para>
  51. <code>getDefaultControllerName()</code>: should return the
  52. name of the default controller.
  53. </para></listitem>
  54. <listitem><para>
  55. <code>getDefaultAction()</code>: should return the
  56. name of the default action.
  57. </para></listitem>
  58. </itemizedlist>
  59. </sect3>
  60. </sect2>
  61. <sect2 id="zend.controller.migration.fromoneohtoonefive">
  62. <title>Migrating from 1.0.x to 1.5.0 or Newer</title>
  63. <para>
  64. Though most basic functionality remains the same, and all documented
  65. functionality remains the same, there is one particular
  66. <emphasis>undocumented</emphasis> "feature" that has changed.
  67. </para>
  68. <para>
  69. When writing URLs, the documented way to write camelCased action
  70. names is to use a word separator; these are '.' or '-' by default,
  71. but may be configured in the dispatcher. The dispatcher internally
  72. lowercases the action name, and uses these word separators to
  73. re-assemble the action method using camelCasing. However, because PHP
  74. functions are not case sensitive, you <emphasis>could</emphasis>
  75. still write URLs using camelCasing, and the dispatcher would resolve
  76. these to the same location. For example, 'camel-cased' would become
  77. 'camelCasedAction' by the dispatcher, whereas 'camelCased' would
  78. become 'camelcasedAction'; however, due to the case insensitivity of
  79. PHP, both will execute the same method.
  80. </para>
  81. <para>
  82. This causes issues with the ViewRenderer when resolving view
  83. scripts. The canonical, documented way is that all word separators
  84. are converted to dashes, and the words lowercased. This creates
  85. a semantic tie between the actions and view scripts, and the
  86. normalization ensures that the scripts can be found. However, if the
  87. action 'camelCased' is called and actually resolves, the word
  88. separator is no longer present, and the ViewRenderer attempts to
  89. resolve to a different location -- 'camelcased.phtml' instead of
  90. 'camel-cased.phtml'.
  91. </para>
  92. <para>
  93. Some developers relied on this "feature", which was never intended.
  94. Several changes in the 1.5.0 tree, however, made it so that the
  95. ViewRenderer no longer resolves these paths; the semantic tie is now
  96. enforced. First among these, the dispatcher now enforces case
  97. sensitivity in action names. What this means is that referring to
  98. your actions on the url using camelCasing will no longer resolve to
  99. the same method as using word separators (i.e., 'camel-casing').
  100. This leads to the ViewRenderer now only honoring the word-separated
  101. actions when resolving view scripts.
  102. </para>
  103. <para>
  104. If you find that you were relying on this "feature", you have several
  105. options:
  106. </para>
  107. <itemizedlist>
  108. <listitem><para>
  109. Best option: rename your view scripts. Pros: forward
  110. compatibility. Cons: if you have many view scripts that
  111. relied on the former, unintended behavior, you will have a
  112. lot of renaming to do.
  113. </para></listitem>
  114. <listitem>
  115. <para>
  116. Second best option: The ViewRenderer now delegates view
  117. script resolution to <classname>Zend_Filter_Inflector</classname>; you
  118. can modify the rules of the inflector to no longer separate
  119. the words of an action with a dash:
  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. The above code will modify the inflector to no longer
  135. separate the words with dash; you may also want to remove
  136. the 'StringToLower' filter if you <emphasis>do</emphasis>
  137. want the actual view script names camelCased as well.
  138. </para>
  139. <para>
  140. If renaming your view scripts would be too tedious or time
  141. consuming, this is your best option until you can find the
  142. time to do so.
  143. </para>
  144. </listitem>
  145. <listitem>
  146. <para>
  147. Least desirable option: You can force the dispatcher to
  148. dispatch camelCased action names with a new front controller
  149. flag, 'useCaseSensitiveActions':
  150. </para>
  151. <programlisting role="php"><![CDATA[
  152. $front->setParam('useCaseSensitiveActions', true);
  153. ]]></programlisting>
  154. <para>
  155. This will allow you to use camelCasing on the url and still
  156. have it resolve to the same action as when you use word
  157. separators. However, this will mean that the original issues
  158. will cascade on through; you will likely need to use the
  159. second option above in addition to this for things to work
  160. at all reliably.
  161. </para>
  162. <para>
  163. Note, also, that usage of this flag will raise a notice that
  164. this usage is deprecated.
  165. </para>
  166. </listitem>
  167. </itemizedlist>
  168. </sect2>
  169. <sect2 id="zend.controller.migration.fromzeroninethree">
  170. <title>Migrating from 0.9.3 to 1.0.0RC1 or Newer</title>
  171. <para>
  172. The principal changes introduced in 1.0.0RC1 are the introduction of
  173. and default enabling of the
  174. <link
  175. linkend="zend.controller.plugins.standard.errorhandler">ErrorHandler</link>
  176. plugin and the <link
  177. linkend="zend.controller.actionhelpers.viewrenderer">ViewRenderer</link>
  178. action helper. Please read the documentation to each thoroughly to
  179. see how they work and what effect they may have on your
  180. applications.
  181. </para>
  182. <para>
  183. The <code>ErrorHandler</code> plugin runs during
  184. <code>postDispatch()</code> checking for exceptions, and forwarding
  185. to a specified error handler controller. You should include such a
  186. controller in your application. You may disable it by setting the
  187. front controller parameter <code>noErrorHandler</code>:
  188. </para>
  189. <programlisting role="php"><![CDATA[
  190. $front->setParam('noErrorHandler', true);
  191. ]]></programlisting>
  192. <para>
  193. The <code>ViewRenderer</code> action helper automates view injection
  194. into action controllers as well as autorendering of view scripts
  195. based on the current action. The primary issue you may encounter is
  196. if you have actions that do not render view scripts and neither
  197. forward or redirect, as the <code>ViewRenderer</code> will attempt
  198. to render a view script based on the action name.
  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. -->