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

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112508 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-10-15 02:53:11 +00:00
parent 3aee3e2b23
commit 3b4d0a7422
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,18 +292,31 @@ 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,
* then this will return the current controller.

View File

@ -115,6 +115,9 @@ class RequestHandler extends ViewableData {
// 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");