The heart of the RewriteRouter is the definition of user defined
routes. Routes are added by calling the addRoute method of
RewriteRouter and passing in a new instance of a class implementing
Rewrite Router comes with six basic types of routes (one of which is special):
Routes may be used numerous times to create a chain or user defined application routing schema. You may use any number of routes in any configuration, with the exception of the Module route, which should rather be used once and probably as the most generic route (i.e., as a default). Each route will be described in greater detail later on.
The first parameter to addRoute is the name of the route. It is used as a handle for getting the routes out of the router (e.g., for URL generation purposes). The second parameter being the route itself.
The most common use of the route name is through the means of
Zend_View url helper:
"<?php echo $this->url(array('username' => 'martel'), 'user') ?>">Martel</a>
Which would result in the href:
Routing is a simple process of iterating through all provided routes
and matching its definitions to current request URI. When a positive
match is found, variable values are returned from the Route instance
and are injected into the
object for later use in the dispatcher as well as in user created
controllers. On a negative match result, the next route in the chain
If you need to determine which route was matched, you can use the
getCurrentRouteName() method, which will return the
identifier used when registering the route with the router. If you
want the actual route object, you can use
Routes are matched in reverse order so make sure your most generic routes are defined first.
Values returned from routing come from URL parameters or user
defined route defaults. These variables are later accessible
There are three special variables which can be used in your routes
- 'module', 'controller' and 'action'. These special variables are
Zend_Controller_Dispatcher to find a controller and
action to dispatch to.
The names of these special variables may be different if you
choose to alter the defaults in
Zend_Controller_Request_Http by means of the