Zend_Controller-Router-Route-Static.xml 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect3 id="zend.controller.router.routes.static">
  4. <title>Zend_Controller_Router_Route_Static</title>
  5. <para>
  6. The examples above all use dynamic routes -- routes that contain
  7. patterns to match against. Sometimes, however, a particular route is
  8. set in stone, and firing up the regular expression engine would be
  9. an overkill. The answer to this situation is to use static routes:
  10. </para>
  11. <programlisting language="php"><![CDATA[
  12. $route = new Zend_Controller_Router_Route_Static(
  13. 'login',
  14. array('controller' => 'auth', 'action' => 'login')
  15. );
  16. $router->addRoute('login', $route);
  17. ]]></programlisting>
  18. <para>
  19. Above route will match a <acronym>URL</acronym> of
  20. <filename>http://domain.com/login</filename>, and dispatch to
  21. <methodname>AuthController::loginAction()</methodname>.
  22. </para>
  23. <note id="zend.controller.router.routes.static.warning">
  24. <title>Warning: Static Routes must Contain Sane Defaults</title>
  25. <para>
  26. Since a static route does not pass any part of the <acronym>URL</acronym> to the
  27. request object as parameters, you <emphasis>must</emphasis> pass
  28. all parameters necessary for dispatching a request as defaults to
  29. the route. Omitting the "controller" or "action" default values will
  30. have unexpected results, and will likely result in the request being
  31. undispatchable.
  32. </para>
  33. <para>
  34. As a rule of thumb, always provide each of the following default
  35. values:
  36. </para>
  37. <itemizedlist>
  38. <listitem><para>controller</para></listitem>
  39. <listitem><para>action</para></listitem>
  40. <listitem><para>module (if not default)</para></listitem>
  41. </itemizedlist>
  42. <para>
  43. Optionally, you can also pass the "useDefaultControllerAlways"
  44. parameter to the front controller during bootstrapping:
  45. </para>
  46. <programlisting language="php"><![CDATA[
  47. $front->setParam('useDefaultControllerAlways', true);
  48. ]]></programlisting>
  49. <para>
  50. However, this is considered a workaround; it is always better to
  51. explicitly define sane defaults.
  52. </para>
  53. </note>
  54. </sect3>
  55. <!--
  56. vim:se ts=4 sw=4 et:
  57. -->