| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?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 <acronym>URL</acronym> of
- <filename>http://domain.com/login</filename>, and dispatch to
- <methodname>AuthController::loginAction()</methodname>.
- </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 <acronym>URL</acronym> 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:
- -->
|