Get and post in cakephp
Asked Answered
C

8

9

In Codeigniter I do this

$p=$this->input->post();

to get all objects posted but I don't know if there is something similar in cakephp to get all posted variables from a form ? I am writing a function to get posted password and save it into database in place of the old password recorded there.

I use native php to get 'posted' variables from a form, (I am not familiar with cakephp form usage) that is why, so instead of using $_POST['sssss'] what should I do now ?

Thank you for any help.

Corps answered 7/3, 2012 at 8:33 Comment(0)
P
14
$value = $this->request->data('key');

Please for further reference, read the manual. It's so much easier and better for yourself to figure it out by yourself.

http://book.cakephp.org/2.0/en/controllers/request-response.html#accessing-post-data

Perceptual answered 7/3, 2012 at 8:39 Comment(2)
This is wrong, data is an array. $value = $this->request->data['key']; would be right.Dependable
Please read the manual, it states: You can either directly access the data property, or you can use CakeRequest::data() to read the data array in an error free manner. Any keys that do not exist will return null:Perceptual
L
6
 for the GET method 
 $this->request->query['category-name'];

 and POST method 
 $this->request->data

http://book.cakephp.org/2.0/en/controllers/request-response.html#accessing-querystring-parameters

Lianneliao answered 2/7, 2013 at 8:12 Comment(0)
P
3

You can check if posted a form by using

if (!empty($this->data)) {
  print_r($this->data);
}
Psychopathist answered 7/3, 2012 at 9:1 Comment(0)
D
2

The Post data must be in data to show up in $this->request->data.

Example:

// input field
<input type="text" name="data[foo]" value="bar" />

// in your controller
debug($this->request->data);
Dependable answered 7/3, 2012 at 8:39 Comment(0)
U
2

To check if posted a form, please use:

if ($this->request->is('post')) {
    pr($this->request->data);
}
Uni answered 17/5, 2013 at 9:36 Comment(0)
Q
2

If you want to get a specific field of the table can move so:

if($this->data["Objetorastreavel"]["id"]){
}

It checks only the ID Objetorestraeval if you want to pick only one field and not post the whole page.

Quest answered 20/5, 2013 at 17:52 Comment(0)
G
1

You should able to access form post data with:

For CakePHP 2.x

if ($this->request->is('post')) {
    pr($this->request->data);
}

For CakePHP 3.4.x

if ($this->request->is('post')) {
    pr($this->request->getData());
}

Documentation for CakePHP 3

Gown answered 29/4, 2017 at 6:54 Comment(0)
N
0

You can use following to retrieve post/get data in CakePHP

For post data: $this->request->data;

For get data: $this->request->query;

Northeasterly answered 10/5, 2017 at 6:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.