ZF-243: Custom route handlers for Zend_Controller_RewriteRouter

Issue Type: Docs: Improvement Created: 2006-07-13T00:08:15.000+0000 Last Updated: 2007-07-05T14:43:14.000+0000 Status: Resolved Fix version(s): - 0.2.0 (29/Oct/06)

Reporter: Michael Sheakoski (michael) Assignee: Nick Lo (nicklo) Tags: - Zend_Controller

Related issues: Attachments:


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

<pre class="literal">
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());


Posted by Michal Minicki (martel) on 2006-07-14T07:42:34.000+0000

Made possible with changeset 914.

Posted by Michael Sheakoski (michael) on 2006-07-14T13:08:29.000+0000

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:

<pre class="literal">
$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:

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

Posted by Gavin (gavin) on 2006-08-31T16:36:59.000+0000

The English manual should be updated to reflect this change.…

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.