Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access a GET request in CAKEPHP?

Tags:

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 ?

like image 761
AnNaMaLaI Avatar asked May 26 '11 05:05

AnNaMaLaI


People also ask

How can I get data from cakephp?

To view records of database, we first need to get hold of a table using the TableRegistry class. We can fetch the instance out of registry using get() method. The get() method will take the name of the database table as argument. Now, this new instance is used to find records from database using find() method.

How can I get post data in cakephp?

You can retrieve post data as Array. $post_data= $this->request->data; You can retrieve post data for particular key.

How can I get full url in cakephp?

Get Current Url in Cakephp : $this->here is used to get the current url in cakephp. it will give you the absolute current url. $this->request->here is also used to get current url.

How can I get URL parameters in cakephp 3?

Cakephp get url parameters Syntax – // Get the Passed arguments $this->request->pass; $this->request['pass']; $this->request->params['pass']; The above syntax will give you the arguments of url passed along with controller.


2 Answers

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

like image 174
Code Commander Avatar answered Oct 20 '22 00:10

Code Commander


The standard way to do this in Cake is to use $this->params.

$value1 = $this->params['url']['key1']; $value2 = $this->params['url']['key2']; 

According to the CakePHP book, "the most common use of $this->params is to access information that has been handed to the controller via GET or POST operations."

See here.

like image 39
declan Avatar answered Oct 19 '22 23:10

declan