ZF-243: Custom route handlers for Zend_Controller_RewriteRouter

Description

I am proposing a slight addition to Zend_Controller_RewriteRouter in order to have the ability to add custom route handlers without having to extend the RewriteRouter class

public function addCustomRoute($name, $routeHandler, $map, $params = array(), $reqs = array())
{
    if (!class_exists($routeHandler)) Zend::loadClass($routeHandler);
    $this->_routes[$name] = new $routeHandler($map, $params, $reqs);
}


Usage: (the % is just there to simulate someone's possible custom route)
$router = new Zend_Controller_RewriteRouter();
$router->addCustomRoute('myRoute', 'Custom_Controller_Router_MyRoute', '%controller/%action/%*{/}', array(), array());
$router->addRoute('news', 'news/:action', array(), array());

Comments

Made possible with changeset 914.

Martel that is very clever how you approached this! I didn't think to do it this way. Just in case anyone looks at this issue here is the new way to add custom routes:

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

Instead of the old way:

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

The English manual should be updated to reflect this change.

http://framework.zend.com/manual/en/…