mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
adding support to write values to param like can be done with data(), method returns $this as does ->data() when writing
This commit is contained in:
parent
9dca564519
commit
bcdc530391
2 changed files with 30 additions and 0 deletions
|
@ -874,6 +874,11 @@ class CakeRequest implements ArrayAccess {
|
|||
* return false if the parameter doesn't exist or is falsey.
|
||||
*/
|
||||
public function param($name) {
|
||||
$args = func_get_args();
|
||||
if (count($args) === 2) {
|
||||
$this->params = Hash::insert($this->params, $name, $args[1]);
|
||||
return $this;
|
||||
}
|
||||
if (!isset($this->params[$name])) {
|
||||
return Hash::get($this->params, $name, false);
|
||||
}
|
||||
|
|
|
@ -2114,6 +2114,31 @@ class CakeRequestTest extends CakeTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function testParamWriting() {
|
||||
$request = new CakeRequest('/');
|
||||
$request->addParams(array(
|
||||
'action' => 'index',
|
||||
));
|
||||
|
||||
$this->assertInstanceOf('CakeRequest', $request->param('some', 'thing'), 'Method has not returned $this');
|
||||
|
||||
$request->param('Post.null', null);
|
||||
$this->assertNull($request->params['Post']['null']);
|
||||
|
||||
$request->param('Post.false', false);
|
||||
$this->assertFalse($request->params['Post']['false']);
|
||||
|
||||
$request->param('Post.zero', 0);
|
||||
$this->assertSame(0, $request->params['Post']['zero']);
|
||||
|
||||
$request->param('Post.empty', '');
|
||||
$this->assertSame('', $request->params['Post']['empty']);
|
||||
|
||||
$this->assertSame('index', $request->action);
|
||||
$request->param('action', 'edit');
|
||||
$this->assertSame('edit', $request->action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test accept language
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue