CakeRequest::param PHP 메소드

param() 공개 메소드

Safely access the values in $this->params.
public param ( string $name ) : mixed
$name string The name of the parameter to get.
리턴 mixed The value of the provided parameter. Will 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);
        }
        return $this->params[$name];
    }

Usage Example

 /**
  * 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);
 }
All Usage Examples Of CakeRequest::param