Sometimes it is more convenient to update a configuration file with
new routes than to change the code. This is possible via the
addConfig() method. Basically, you create a
Zend_Config-compatible configuration, and in your code read it in
and pass it to the RewriteRouter.
As an example, consider the following INI file:
routes.archive.route = "archive/:year/*"
routes.archive.defaults.controller = archive
routes.archive.defaults.action = show
routes.archive.defaults.year = 2000
routes.archive.reqs.year = "\d+"
routes.news.type = "Zend_Controller_Router_Route_Static"
routes.news.route = "news"
routes.news.defaults.controller = "news"
routes.news.defaults.action = "list"
routes.archive.type = "Zend_Controller_Router_Route_Regex"
routes.archive.route = "archive/(\d+)"
routes.archive.defaults.controller = "archive"
routes.archive.defaults.action = "show"
routes.archive.map.1 = "year"
; OR: routes.archive.map.year = 1
The above INI file can then be read into a
Zend_Config object as follows:
$config = new Zend_Config_Ini('/path/to/config.ini', 'production');
$router = new Zend_Controller_Router_Rewrite();
In the above example, we tell the router to use the 'routes' section
of the INI file to use for its routes. Each first-level key under
that section will be used to define a route name; the above example
defines the routes 'archive' and 'news'. Each route then requires,
at minimum, a 'route' entry and one or more 'defaults' entries;
optionally one or more 'reqs' (short for 'required') may be
provided. All told, these correspond to the three arguments provided
Zend_Controller_Router_Route_Interface object. An
option key, 'type', can be used to specify the route class type to
use for that particular route; by default, it uses
Zend_Controller_Router_Route. In the example above, the
'news' route is defined to use