1
votes

CakePHP documentation says:

Typically REST applications not only output content in alternate data formats, but also accept data in different formats. In CakePHP, the RequestHandlerComponent helps facilitate this. By default, it will decode any incoming JSON/XML input data for POST/PUT requests and supply the array version of that data in $this->request->data. source

But my $this->request->data is empty array.

In AppController.php I load $this->loadComponent('RequestHandler');

That's my RequestHandler debug info

enter image description here

My request data:

Accept: application/json Content-Type: application/json

{"store_id": 671}

And my request data always is empty, why?

2
how looks your request url? - Salines
just post data through GET and check it they are empty or not. Ex: http://localhost/URL?key=test - Aman Rawat
request url: http://localhost/MenuItems/add - Marcin K.
this problem occurs only if request is in json or xml - Marcin K.
When you say "my request data", do you mean that this is what you have sent, or that this is what your app receives, and you know because you've debugged that? Also where exactly in our app are you testing $this->request->data? - ndm

2 Answers

0
votes

PHP doesn't read POST data if it's in JSON format by default. I'm not familiar with CakePHP, so I can't help there, but the way I typically handle it is:

$JSON = json_decode(file_get_contents('php://input'), true);
echo $JSON['store_id'];
0
votes

Debug info is from isAuthorized. in that event JSON data in available only by $this->request->input('json_decode');