Permalink
Browse files

Merge branch 'prg-use-params' of https://github.com/bakura10/zf2

  • Loading branch information...
2 parents 9c85cc3 + ebf819e commit ceeccff9d00643ea92ce094f891f2374cbcf28e6 @weierophinney weierophinney committed Sep 4, 2012
@@ -27,9 +27,13 @@ public function __invoke($redirect = null, $redirectToUrl = false)
{
$controller = $this->getController();
$request = $controller->getRequest();
+ $params = array();
if (null === $redirect) {
- $redirect = $controller->getEvent()->getRouteMatch()->getMatchedRouteName();
+ $routeMatch = $controller->getEvent()->getRouteMatch();
+
+ $redirect = $routeMatch->getMatchedRouteName();
+ $params = $routeMatch->getParams();
}
$container = new Container('prg_post1');
@@ -42,9 +46,8 @@ public function __invoke($redirect = null, $redirectToUrl = false)
// get the redirect plugin from the plugin manager
$redirector = $controller->getPluginManager()->get('Redirect');
} else {
-
/*
- * if the user wants to redirect to a route, the redirector has to come
+ * If the user wants to redirect to a route, the redirector has to come
* from the plugin manager -- otherwise no router will be injected
*/
if ($redirectToUrl === false) {
@@ -55,13 +58,14 @@ public function __invoke($redirect = null, $redirectToUrl = false)
}
if ($redirectToUrl === false) {
- $response = $redirector->toRoute($redirect);
+ $response = $redirector->toRoute($redirect, $params);
$response->setStatusCode(303);
return $response;
}
$response = $redirector->toUrl($redirect);
$response->setStatusCode(303);
+
return $response;
} else {
if ($container->post !== null) {
@@ -16,6 +16,7 @@
use Zend\Http\Response;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\Router\Http\Literal as LiteralRoute;
+use Zend\Mvc\Router\Http\Segment as SegmentRoute;
use Zend\Mvc\Router\RouteMatch;
use Zend\Mvc\Router\SimpleRouteStack;
use Zend\Stdlib\Parameters;
@@ -41,7 +42,14 @@ public function setUp()
'route' => '/',
'defaults' => array(
'controller' => 'ZendTest\Mvc\Controller\TestAsset\SampleController',
- ),
+ )
+ )));
+
+ $router->addRoute('sub', SegmentRoute::factory(array(
+ 'route' => '/foo/:param',
+ 'defaults' => array(
+ 'param' => 1
+ )
)));
$this->controller = new SampleController();
@@ -126,7 +134,6 @@ public function testNullRouteUsesMatchedRouteName()
'postval1' => 'value1'
)));
-
$result = $this->controller->dispatch($this->request, $this->response);
$prgResultRoute = $this->controller->prg();
@@ -135,4 +142,22 @@ public function testNullRouteUsesMatchedRouteName()
$this->assertEquals('/', $prgResultRoute->getHeaders()->get('Location')->getUri());
$this->assertEquals(303, $prgResultRoute->getStatusCode());
}
+
+ public function testReuseMatchedParameters()
+ {
+ $this->controller->getEvent()->getRouteMatch()->setMatchedRouteName('sub');
+
+ $this->request->setMethod('POST');
+ $this->request->setPost(new Parameters(array(
+ 'postval1' => 'value1'
+ )));
+
+ $this->controller->dispatch($this->request, $this->response);
+ $prgResultRoute = $this->controller->prg();
+
+ $this->assertInstanceOf('Zend\Http\Response', $prgResultRoute);
+ $this->assertTrue($prgResultRoute->getHeaders()->has('Location'));
+ $this->assertEquals('/foo/1', $prgResultRoute->getHeaders()->get('Location')->getUri());
+ $this->assertEquals(303, $prgResultRoute->getStatusCode());
+ }
}

0 comments on commit ceeccff

Please sign in to comment.