diff --git a/core/control/Director.php b/core/control/Director.php index 783ba70bc..82ebc8a0e 100755 --- a/core/control/Director.php +++ b/core/control/Director.php @@ -275,8 +275,6 @@ class Director { return "redirect:" . Director::absoluteURL($arguments['Redirect'], true); } else { - Director::$urlParams = $arguments; - $controllerObj = new $controller(); $controllerObj->setSession($session); @@ -294,17 +292,30 @@ class Director { /** * Returns the urlParam with the given name + * + * @deprecated 3.0 Use SS_HTTPRequest->latestParam() */ static function urlParam($name) { if(isset(Director::$urlParams[$name])) return Director::$urlParams[$name]; } /** - * Returns an array of urlParams + * Returns an array of urlParams. + * + * @deprecated 3.0 Use SS_HTTPRequest->latestParams() */ static function urlParams() { return Director::$urlParams; } + + /** + * Set url parameters (should only be called internally by RequestHandler->handleRequest()). + * + * @param $params array + */ + static function setUrlParams($params) { + Director::$urlParams = $params; + } /** * Return the {@link SiteTree} object that is currently being viewed. If there is no sitetree object to return, diff --git a/core/control/RequestHandler.php b/core/control/RequestHandler.php index 10f4c3427..27c56e0c6 100755 --- a/core/control/RequestHandler.php +++ b/core/control/RequestHandler.php @@ -114,6 +114,9 @@ class RequestHandler extends ViewableData { if($params = $request->match($rule, true)) { // FIXME: This unnecessary coupling was added to fix a bug in Image_Uploader. if($this instanceof Controller) $this->urlParams = $request->allParams(); + + // Backwards compatible setting of url parameters, please use SS_HTTPRequest->latestParam() instead + Director::setUrlParams($request->latestParams()); if(isset($_REQUEST['debug_request'])) { Debug::message("Rule '$rule' matched to action '$action' on $this->class. Latest request params: " . var_export($request->latestParams(), true)); diff --git a/tests/RequestHandlingTest.php b/tests/RequestHandlingTest.php index 52aaec8c7..bb16d42bb 100755 --- a/tests/RequestHandlingTest.php +++ b/tests/RequestHandlingTest.php @@ -7,6 +7,23 @@ class RequestHandlingTest extends SapphireTest { static $fixture_file = null; + // function testRequestHandlerChainingLatestParams() { + // $c = new RequestHandlingTest_Controller(); + // $c->init(); + // $response = $c->handleRequest(new SS_HTTPRequest('GET', 'testGoodBase1/TestForm/fields/MyField')); + // $this->assertEquals( + // $c->getRequest()->latestParams(), + // array( + // 'Action' => 'fields', + // 'ID' => 'MyField' + // ) + // ); + // } + + function testRequestHandlerChainingAllParams() { + // TODO + } + function testMethodCallingOnController() { /* Calling a controller works just like it always has */ $response = Director::test("testGoodBase1"); @@ -40,7 +57,7 @@ class RequestHandlingTest extends SapphireTest { $response = Director::test("testGoodBase1/TestForm/fields/MyField" ,array("MyField" => 5)); $this->assertEquals("MyField posted, update to 5", $response->getBody()); } - + function testBadBase() { /* Without a double-slash indicator in the URL, the entire URL is popped off the stack. The controller's default action handlers have been designed for this to an extend: simple actions can still be called. This is the set-up