5.4. Variable defaults
Prev | Chapter 5. Zend_Controller_RewriteRouter | Next

## 5.4. Variable defaults

Every variable in the route can have a default. To provide it you have to add a third parameter to the addRoute method. This third parameter is an array with keys as variable names and values as desired defaults.

    $router->addRoute('archive', 'archive/:year', array('year' => 2006));

What may not be clearly visible is that the above route will match URLs like 'http://example.com/archive/2005' and 'http://example.com/archive'. In the latter case the variable year will have a value of 2006.

In the above example we haven't set a controller so it will always result in a noRoute action of an IndexController. To make it usable you have to provide a valid controller and a valid action as a default:

    $router->addRoute('archive', 'archive/:year', array('year' => 2006, 'controller' => 'archive', 'action' => 'show'));

Prev | Up | Next
5.3. Basic Routes | Home | 5.5. Variable requirements