mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
3aee3e2b23
commit
3b4d0a7422
@ -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,
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user