| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect3 id="zend.controller.router.routes.static">
- <title>Zend_Controller_Router_Route_Static</title>
- <para>
- The examples above all use dynamic routes -- routes that contain
- patterns to match against. Sometimes, however, a particular route is
- set in stone, and firing up the regular expression engine would be
- an overkill. The answer to this situation is to use static routes:
- </para>
- <programlisting language="php"><![CDATA[
- $route = new Zend_Controller_Router_Route_Static(
- 'login',
- array('controller' => 'auth', 'action' => 'login')
- );
- $router->addRoute('login', $route);
- ]]></programlisting>
- <para>
- Above route will match a URL of <code>http://domain.com/login</code>,
- and dispatch to <code>AuthController::loginAction()</code>.
- </para>
- <note id="zend.controller.router.routes.static.warning">
- <title>Warning: Static Routes must Contain Sane Defaults</title>
- <para>
- Since a static route does not pass any part of the URL to the
- request object as parameters, you <emphasis>must</emphasis> pass
- all parameters necessary for dispatching a request as defaults to
- the route. Omitting the "controller" or "action" default values will
- have unexpected results, and will likely result in the request being
- undispatchable.
- </para>
- <para>
- As a rule of thumb, always provide each of the following default
- values:
- </para>
- <itemizedlist>
- <listitem><para>controller</para></listitem>
- <listitem><para>action</para></listitem>
- <listitem><para>module (if not default)</para></listitem>
- </itemizedlist>
- <para>
- Optionally, you can also pass the "useDefaultControllerAlways"
- parameter to the front controller during bootstrapping:
- </para>
- <programlisting language="php"><![CDATA[
- $front->setParam('useDefaultControllerAlways', true);
- ]]></programlisting>
- <para>
- However, this is considered a workaround; it is always better to
- explicitly define sane defaults.
- </para>
- </note>
- </sect3>
- <!--
- vim:se ts=4 sw=4 et:
- -->
|