From 975f74bb440e31af0823301c36bf35796e9c3b34 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 28 Apr 2011 22:42:50 -0400 Subject: [PATCH] Making it so all POST parameters are available on $this->data inside the request. This makes one fewer place POST data is found. $this->params['form'] is still around as well for Backwards compatibility, but is not recommended for use going forward. --- lib/Cake/Network/CakeRequest.php | 19 +++++++++++++++---- .../tests/Case/Network/CakeRequestTest.php | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 7aa0ced43..7dea69cce 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -133,6 +133,8 @@ class CakeRequest implements ArrayAccess { /** * process the post data and set what is there into the object. + * The raw post is available at $this->params['form'], while a lightly processed + * version is available at $this->data * * @return void */ @@ -150,11 +152,12 @@ class CakeRequest implements ArrayAccess { } else { $_ENV['REQUEST_METHOD'] = $this->params['form']['_method']; } - unset($this->params['form']['_method']); } - if (isset($this->params['form']['data'])) { - $this->data = $this->params['form']['data']; - unset($this->params['form']['data']); + $this->data = $this->params['form']; + if (isset($this->data['data'])) { + $data = $this->data['data']; + unset($this->data['data']); + $this->data = Set::merge($this->data, $data); } } @@ -533,6 +536,14 @@ class CakeRequest implements ArrayAccess { /** * Get the HTTP method used for this request. + * There are a few ways to specify a method. + * + * - If your client supports it you can use native HTTP methods. + * - You can set the HTTP-X-Method-Override header. + * - You can submit an input with the name `_method` + * + * Any of these 3 approaches can be used to set the HTTP method used + * by CakePHP internally, and will effect the result of this method. * * @return string The name of the HTTP method used. */ diff --git a/lib/Cake/tests/Case/Network/CakeRequestTest.php b/lib/Cake/tests/Case/Network/CakeRequestTest.php index 095ba4496..d0cdaf719 100644 --- a/lib/Cake/tests/Case/Network/CakeRequestTest.php +++ b/lib/Cake/tests/Case/Network/CakeRequestTest.php @@ -160,7 +160,8 @@ class CakeRequestTestCase extends CakeTestCase { $_POST = array('one' => 1, 'two' => 'three'); $request = new CakeRequest('some/path'); - $this->assertEqual($request->params['form'], $_POST); + $this->assertEquals($_POST, $request->params['form']); + $this->assertEquals($_POST, $request->data); } /**