Browse Source

adding query() for CakeRequest

euromark 13 years ago
parent
commit
e8cfac0eec
2 changed files with 28 additions and 0 deletions
  1. 10 0
      lib/Cake/Network/CakeRequest.php
  2. 18 0
      lib/Cake/Test/Case/Network/CakeRequestTest.php

+ 10 - 0
lib/Cake/Network/CakeRequest.php

@@ -759,6 +759,16 @@ class CakeRequest implements ArrayAccess {
 	}
 
 /**
+ * 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.
  *

+ 18 - 0
lib/Cake/Test/Case/Network/CakeRequestTest.php

@@ -1679,6 +1679,24 @@ class CakeRequestTest extends CakeTestCase {
 	}
 
 /**
+ * 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