Zend_Controller-Migration.xml 33 KB

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