diff --git a/library/Zend/Mvc/Controller/Plugin/Forward.php b/library/Zend/Mvc/Controller/Plugin/Forward.php index 39a7f9df40a..a7eb96b67c5 100644 --- a/library/Zend/Mvc/Controller/Plugin/Forward.php +++ b/library/Zend/Mvc/Controller/Plugin/Forward.php @@ -135,11 +135,15 @@ public function dispatch($name, array $params = null) } } - // Allow passing parameters to seed the RouteMatch with + + // Allow passing parameters to seed the RouteMatch with & copy matched route name if ($params !== null) { - $event->setRouteMatch(new RouteMatch($params)); + $routeMatch = new RouteMatch($params); + $routeMatch->setMatchedRouteName($event->getRouteMatch()->getMatchedRouteName()); + $event->setRouteMatch($routeMatch); } + if ($this->numNestedForwards > $this->maxNestedForwards) { throw new Exception\DomainException("Circular forwarding detected: greater than $this->maxNestedForwards nested forwards"); } diff --git a/tests/ZendTest/Mvc/Controller/Plugin/ForwardTest.php b/tests/ZendTest/Mvc/Controller/Plugin/ForwardTest.php index a8019f5745c..d66f8445acc 100644 --- a/tests/ZendTest/Mvc/Controller/Plugin/ForwardTest.php +++ b/tests/ZendTest/Mvc/Controller/Plugin/ForwardTest.php @@ -41,7 +41,10 @@ public function setUp() $event->setApplication($mockApplication); $event->setRequest(new Request()); $event->setResponse(new Response()); - $event->setRouteMatch(new RouteMatch(array('action' => 'test'))); + + $routeMatch = new RouteMatch(array('action' => 'test')); + $routeMatch->setMatchedRouteName('some-route'); + $event->setRouteMatch($routeMatch); $locator = new Locator; $locator->add('forward', function() { @@ -129,17 +132,20 @@ public function testDispatchWillSeedRouteMatchWithPassedParameters() public function testRouteMatchObjectRemainsSameFollowingForwardDispatch() { - $routeMatch = $this->controller->getEvent()->getRouteMatch(); - $matchParams = $routeMatch->getParams(); + $routeMatch = $this->controller->getEvent()->getRouteMatch(); + $matchParams = $routeMatch->getParams(); + $matchMatchedRouteName = $routeMatch->getMatchedRouteName(); $result = $this->plugin->dispatch('forward', array( 'action' => 'test-matches', 'param1' => 'foobar', )); - $test = $this->controller->getEvent()->getRouteMatch(); - $testParams = $test->getParams(); + $testMatch = $this->controller->getEvent()->getRouteMatch(); + $testParams = $testMatch->getParams(); + $testMatchedRouteName = $testMatch->getMatchedRouteName(); - $this->assertSame($routeMatch, $test); + $this->assertSame($routeMatch, $testMatch); $this->assertEquals($matchParams, $testParams); + $this->assertEquals($matchMatchedRouteName, $testMatchedRouteName); } public function testAllowsPassingEmptyArrayOfRouteParams()