You can retrieve post data as Array.
$post_data= $this->request->data;
You can retrieve post data for particular key.
$this->request->data['field'];
Retrieve specific key value
$this->request->data('key_name');
Retrieve specific key value of nested array
$this->request->data('data.subfield');
the difference between the array notation and data()
method is that data()
is error safe and returns null
if the key does not exist in the array
so intead of doing
if(isset($this->request->data['field']) && $this->request->data['field']) { ...}
you can do
if($this->request->data('field')) { ...}
for CakePHP 3.4.x +
get all data:
$this->request->getData();
get specific key:
$this->request->getData('key');
to set data available for getData function you have to do something like:
$this->request = $this->request->withData('some_key_on_the_fly', 'value');
$some_key_on_the_fly = $this->request->getData('some_key_on_the_fly');
useful for updating the models in controller with static data