Zend_Controller-Router-Route-Static.xml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 URL of <filename>http://domain.com/login</filename>,
  20. and dispatch to <methodname>AuthController::loginAction()</methodname>.
  21. </para>
  22. <note id="zend.controller.router.routes.static.warning">
  23. <title>Warning: Static Routes must Contain Sane Defaults</title>
  24. <para>
  25. Since a static route does not pass any part of the URL to the
  26. request object as parameters, you <emphasis>must</emphasis> pass
  27. all parameters necessary for dispatching a request as defaults to
  28. the route. Omitting the "controller" or "action" default values will
  29. have unexpected results, and will likely result in the request being
  30. undispatchable.
  31. </para>
  32. <para>
  33. As a rule of thumb, always provide each of the following default
  34. values:
  35. </para>
  36. <itemizedlist>
  37. <listitem><para>controller</para></listitem>
  38. <listitem><para>action</para></listitem>
  39. <listitem><para>module (if not default)</para></listitem>
  40. </itemizedlist>
  41. <para>
  42. Optionally, you can also pass the "useDefaultControllerAlways"
  43. parameter to the front controller during bootstrapping:
  44. </para>
  45. <programlisting language="php"><![CDATA[
  46. $front->setParam('useDefaultControllerAlways', true);
  47. ]]></programlisting>
  48. <para>
  49. However, this is considered a workaround; it is always better to
  50. explicitly define sane defaults.
  51. </para>
  52. </note>
  53. </sect3>
  54. <!--
  55. vim:se ts=4 sw=4 et:
  56. -->