ZF-8812: Zend_Controller_Router_Route_Chain fails with some combinations of routes in the chain


Here are the pieces of relevant code and test cases:

$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$request = new Zend_Controller_Request_Http();

$languageRoute = new Zend_Controller_Router_Route_Regex('([a-z]{2})?', array('language' => 'xx'), array(1 => 'language'), '%s');
$moduleRoute = new Zend_Controller_Router_Route_Module(array(), Zend_Controller_Front::getInstance()->getDispatcher(), $request);
$defaultRoute = $languageRoute->chain($moduleRoute);
$router->addRoute('default', $defaultRoute);

Inside the {{match()}} method of Zend_Controller_Router_Route_Chain, if the request URI is {{'/en/'}} or {{'/en'}}, then {{$subPath}} will become {{bool(false)}} after the {{match()}} call to the regex route. Therefore, not only will the module route never get picked up, but the match() method of the chain route will return {{bool(false)}}.

I was able to patch this by changing:

if ($key > 0 && $matchedPath !== null) {


if ($key > 0 && $matchedPath !== null && $subPath !== '' && $subPath !== false) {



Assigning to Ben.

I'm using Ziad's patch that solve similar case.

resources.router.routes.defaultmodule.type = Zend_Controller_Router_Route_Module resources.router.routes.defaultmodule.defaults.module = "default" resources.router.routes.defaultmodule.defaults.controller = "index" resources.router.routes.defaultmodule.defaults.action = "index"

resources.router.routes.language.type = Zend_Controller_Router_Route resources.router.routes.language.route = ":language" resources.router.routes.language.reqs.language = "^(it|fr|en|de)$" resources.router.routes.language.defaults.language = "en"

resources.router.routes.default.type = Zend_Controller_Router_Route_Chain resources.router.routes.default.chain = "language, defaultmodule"

Hello, could you change the priority of this task? I have to patch every new release to do work route chain defaults value. Thanks, great work.

also tested with 1.10.1

resources.frontcontroller.defaultModule = "default" resources.frontcontroller.controllerDirectory = APPLICATION_PATH "/controllers" resources.frontcontroller.moduleDirectory = APPLICATION_PATH "/modules"

resources.router.routes.defaultRoute.type = Zend_Controller_Router_Route_Module" resources.router.routes.defaultRoute.abstract = "On" resources.router.routes.defaultRoute.route = ":module" resources.router.routes.defaultRoute.defaults.module = "default"

resources.router.routes.language.type = "Zend_Controller_Router_Route" resources.router.routes.language.route = ":lang" resources.router.routes.language.reqs.lang = "^(en|de)$" resources.router.routes.language.defaults.lang = "en"

resources.router.routes.default.type = "Zend_Controller_Router_Route_Chain" resources.router.routes.default.chain = "language, defaultRoute"

test url -> request-object

/ -> /en/default/index/index /en -> /en/default/index/index /de -> /de/default/index/index /en/admin/index/index -> /en/admin/index/index /en/index -> /en/default/index/index

works all great. i think, this is a blocker.

Patch and unit test added.

To get unit test work, patch from ZF-10536 should be added first.

Applied to both trunk and 1.11 release branch -- thanks!