Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding query() for CakeRequest

  • Loading branch information...
commit e8cfac0eecd5323b0382d36b72b131902b9261c5 1 parent 144761c
@dereuromark dereuromark 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
18 lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -1679,6 +1679,24 @@ 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 data() method reading
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.