param() public method

Safely access the values in $this->params.
public param ( string $name ) : mixed
$name string 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.
 /**
  * test writing request params with param()
  *
  * @return void
  */
 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);
 }
Esempio n. 2
0
 /**
  * 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'));
 }