mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #1116 from markstory/request-param
Add CakeRequest::param()
This commit is contained in:
commit
64cf42bf42
2 changed files with 34 additions and 0 deletions
|
@ -805,6 +805,20 @@ class CakeRequest implements ArrayAccess {
|
|||
return Hash::get($this->data, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely access the values in $this->params.
|
||||
*
|
||||
* @param string $name The name of the parameter to get.
|
||||
* @return mixed The value of the provided parameter. Will
|
||||
* return false if the parameter doesn't exist or is falsey.
|
||||
*/
|
||||
public function param($name) {
|
||||
if (!isset($this->params[$name])) {
|
||||
return false;
|
||||
}
|
||||
return $this->params[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Read data from `php://input`. Useful when interacting with XML or JSON
|
||||
* request body content.
|
||||
|
|
|
@ -1768,6 +1768,26 @@ class CakeRequestTest extends CakeTestCase {
|
|||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test using param()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadingParams() {
|
||||
$request = new CakeRequest();
|
||||
$request->addParams(array(
|
||||
'controller' => 'posts',
|
||||
'admin' => true,
|
||||
'truthy' => 1,
|
||||
'zero' => '0',
|
||||
));
|
||||
$this->assertFalse($request->param('not_set'));
|
||||
$this->assertTrue($request->param('admin'));
|
||||
$this->assertEquals(1, $request->param('truthy'));
|
||||
$this->assertEquals('posts', $request->param('controller'));
|
||||
$this->assertEquals('0', $request->param('zero'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test the data() method reading
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue