How can I access a GET request in CAKEPHP?

AnNaMaLaI picture AnNaMaLaI · May 26, 2011 · Viewed 44.4k times · Source

How can I access a GET request in CAKEPHP ?

If I am passing a variable in the url

http://samplesite.com/page?key1=value1&key2=value2

Should I use $_GET or $this->params to get the values in controller? What is the standard in CAKEPHP ?

Answer

Code Commander picture Code Commander · Jun 26, 2012

In CakePHP 2.0 this appears to have changed. According to the documentation you can access $this->request->query or $this->request['url'].

// url is /posts/index?page=1&sort=title
$this->request->query['page'];

// You can also access it via array access
$this->request['url']['page'];

http://book.cakephp.org/2.0/en/controllers/request-response.html