Skip to content

Loading…

Updated Page\Mvc::getHref to grab correct controller name from routeMatc... #4184

Closed
wants to merge 1 commit into from

2 participants

@mpinkston

...h when using ModuleRouteListener

If the controller param was being inherited from the routeMatch when ModuleRouteListener is used, the wrong name was being returned. This also removes ModuleRouteListener specific params from being assembled and returned for routes such as wildcard.

@mpinkston

I'm a little lost as to why Page\Mvc::getHref even uses the route match object to populate params in the first place?

In any given request there should only be one routeMatch object, and I inject that into all of my Mvc pages so isActive can return an accurate answer. However, if the same routeMatch object is being used in all Mvc pages, that means unwanted params might get passed along when the route is assembled for getHref.

@weierophinney weierophinney added a commit that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/4184' into develop
Forward port #4184
49a0e5e
@weierophinney weierophinney added a commit that closed this pull request
@weierophinney weierophinney Merge branch 'hotfix/4184'
Close #4184
bd3ab00
@ghost Unknown pushed a commit that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/4184'
Close #4184
d61d3ed
@ghost Unknown pushed a commit that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/4184' into develop
Forward port #4184
1624fee
@weierophinney weierophinney added a commit to zendframework/zend-navigation that referenced this pull request
@weierophinney weierophinney Merge pull request zendframework/zf2#4184 from mpinkston/hotfix/navig…
…ation-page-mvc-getHref-moduleRouteListenerParams

Updated Page\Mvc::getHref to grab correct controller name from routeMatc...
d5c022f
@weierophinney weierophinney added a commit to zendframework/zend-navigation that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/4184' 86b30ce
@weierophinney weierophinney added a commit to zendframework/zend-navigation that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/4184' into develop d5645bf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 4, 2013
  1. @mpinkston

    Updated Page\Mvc::getHref to grab correct controller name from routeM…

    mpinkston committed
    …atch when using ModuleRouteListener
Showing with 41 additions and 1 deletion.
  1. +12 −1 library/Zend/Navigation/Page/Mvc.php
  2. +29 −0 tests/ZendTest/Navigation/Page/MvcTest.php
View
13 library/Zend/Navigation/Page/Mvc.php
@@ -191,7 +191,18 @@ public function getHref()
}
if ($this->getRouteMatch() !== null) {
- $params = array_merge($this->getRouteMatch()->getParams(), $this->getParams());
+ $rmParams = $this->getRouteMatch()->getParams();
+
+ if (isset($rmParams[ModuleRouteListener::ORIGINAL_CONTROLLER])) {
+ $rmParams['controller'] = $rmParams[ModuleRouteListener::ORIGINAL_CONTROLLER];
+ unset($rmParams[ModuleRouteListener::ORIGINAL_CONTROLLER]);
+ }
+
+ if (isset($rmParams[ModuleRouteListener::MODULE_NAMESPACE])) {
+ unset($rmParams[ModuleRouteListener::MODULE_NAMESPACE]);
+ }
+
+ $params = array_merge($rmParams, $this->getParams());
} else {
$params = $this->getParams();
}
View
29 tests/ZendTest/Navigation/Page/MvcTest.php
@@ -561,5 +561,34 @@ public function testMvcPageParamsInheritRouteMatchParams()
$this->assertEquals('/lollerblades/view/23', $page->getHref());
}
+ public function testInheritedRouteMatchParamsWorkWithModuleRouteListener()
+ {
+ $page = new Page\Mvc(array(
+ 'label' => 'mpinkstonwashere',
+ 'route' => 'lmaoplane'
+ ));
+
+ $route = new SegmentRoute('/lmaoplane/:controller');
+
+ $router = new TreeRouteStack;
+ $router->addRoute('lmaoplane', $route);
+
+ $routeMatch = new RouteMatch(array(
+ ModuleRouteListener::MODULE_NAMESPACE => 'Application\Controller',
+ 'controller' => 'index'
+ ));
+ $routeMatch->setMatchedRouteName('lmaoplane');
+
+ $event = new MvcEvent();
+ $event->setRouter($router)
+ ->setRouteMatch($routeMatch);
+ $moduleRouteListener = new ModuleRouteListener();
+ $moduleRouteListener->onRoute($event);
+
+ $page->setRouter($event->getRouter());
+ $page->setRouteMatch($event->getRouteMatch());
+
+ $this->assertEquals('/lmaoplane/index', $page->getHref());
+ }
}
Something went wrong with that request. Please try again.