adding query() for CakeRequest

This commit is contained in:
euromark 2012-09-18 19:38:53 +02:00
parent 144761c0b2
commit e8cfac0eec
2 changed files with 28 additions and 0 deletions

View file

@ -758,6 +758,16 @@ class CakeRequest implements ArrayAccess {
return $accept;
}
/**
* 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 file

@ -1678,6 +1678,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
*