Zend_Controller-Router-Route-Hostname.xml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect3 id="zend.controller.router.routes.hostname">
  4. <title>Zend_Controller_Router_Route_Hostname</title>
  5. <para>
  6. <classname>Zend_Controller_Router_Route_Hostname</classname> is the hostname route of
  7. the framework. It works similar to the standard route, but it works on
  8. the with the hostname of the called <acronym>URL</acronym> instead with the path.
  9. </para>
  10. <para>
  11. Let's use the example from the standard route and see how it would look
  12. like in a hostname based way. Instead of calling the user via a path,
  13. we'd want to have a user to be able to call
  14. <filename>http://martel.users.example.com</filename> to see the information
  15. about the user "martel":
  16. </para>
  17. <programlisting language="php"><![CDATA[
  18. $hostnameRoute = new Zend_Controller_Router_Route_Hostname(
  19. ':username.users.example.com',
  20. array(
  21. 'controller' => 'profile',
  22. 'action' => 'userinfo'
  23. )
  24. );
  25. $plainPathRoute = new Zend_Controller_Router_Route_Static('');
  26. $router->addRoute('user', $hostnameRoute->chain($plainPathRoute));
  27. ]]></programlisting>
  28. <para>
  29. The first parameter in the <classname>Zend_Controller_Router_Route_Hostname</classname>
  30. constructor is a route definition that will be matched to a hostname. Route
  31. definitions consist of static and dynamic parts separated by the dot
  32. ('.') character. Dynamic parts, called variables, are marked by
  33. prepending a colon to the variable name: <command>:username</command>.
  34. Static parts are just simple text: <command>user</command>.
  35. </para>
  36. <para>
  37. Hostname routes can, but never should be used as is. The reason behind
  38. that is, that a hostname route alone would match any path. So what you
  39. have to do is to chain a path route to the hostname route. This is done
  40. like in the example by calling <command>$hostnameRoute->chain($pathRoute);</command>.
  41. By doing this, <varname>$hostnameRoute</varname> isn't modified, but a new
  42. route (<classname>Zend_Controller_Router_Route_Chain</classname>) is returned,
  43. which can then be given to the router.
  44. </para>
  45. </sect3>
  46. <!--
  47. vim:se ts=4 sw=4 et:
  48. -->