Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #858 from dereuromark/2.3-request

adding query() for CakeRequest
  • Loading branch information...
commit e931211fcc8884eef53bd2f9c18c27fd6eb7b39d 2 parents 99cbd22 + 60385d1
@markstory markstory authored
View
10 lib/Cake/Network/CakeRequest.php
@@ -759,6 +759,16 @@ protected static function _parseAcceptWithQualifier($header) {
}
/**
+ * Provides a read accessor for `$this->query`. Allows you
+ * to use a syntax similar to `CakeSession` for reading url query data.
+ *
+ * @return mixed The value being read
+ */
+ public function query($name) {
+ return Hash::get($this->query, $name);
+ }
+
+/**
* Provides a read/write accessor for `$this->data`. Allows you
* to use a syntax similar to `CakeSession` for reading post data.
*
View
39 lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -1679,6 +1679,45 @@ public function testEnvironmentDetection($name, $env, $expected) {
}
/**
+ * test the query() method
+ *
+ * @return void
+ */
+ public function testQuery() {
+ $_GET = array();
+ $_GET['foo'] = 'bar';
+
+ $request = new CakeRequest();
+
+ $result = $request->query('foo');
+ $this->assertEquals('bar', $result);
+
+ $result = $request->query('imaginary');
+ $this->assertNull($result);
+ }
+
+/**
+ * test the query() method with arrays passed via $_GET
+ *
+ * @return void
+ */
+ public function testQueryWithArray() {
+ $_GET = array();
+ $_GET['test'] = array('foo', 'bar');
+
+ $request = new CakeRequest();
+
+ $result = $request->query('test');
+ $this->assertEquals(array('foo', 'bar'), $result);
+
+ $result = $request->query('test.1');
+ $this->assertEquals('bar', $result);
+
+ $result = $request->query('test.2');
+ $this->assertNull($result);
+ }
+
+/**
* test the data() method reading
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.