1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
<?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:
-->
|