ENHANCEMENT: Added method for $this->request->latestParam() backwards compatibility with Director::urlParam()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@105890 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Carlos Barberis 2010-05-28 04:17:36 +00:00 committed by Sam Minnee
parent ca9f32f9ec
commit 3bbcb31364
3 changed files with 35 additions and 4 deletions

View File

@ -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,

View File

@ -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));

View File

@ -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