'Phalcon 5 - Sending post request to controller results in empty post data
I'm using a docker setup with php 8.0.15 + phalcon 5.0.0beta2 and i'm trying to do a simple post request using the fetch api to a route.
/* inside router.php */
$apiGroup = new Router\Group();
$apiGroup->setPrefix('/api');
$apiGroup->addPost('/user', 'UserApi::post');
/* somewhere in my controller action */
$data = [
'email' => $this->request->getPost('email', [ Filter::FILTER_EMAIL ]),
'password' => $this->request->getPost('password', [ Filter::FILTER_STRING ]),
];
/* in my js */
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(someData)
}).then(dostuff);
My problem is that $this->request->getPost('email') returns null and when debugging I saw that $_POST is also empty. Using $this->request->getRawBody() and $this->request->getJsonRawBody() do yield results since my data is actually there. I could very well just use getJsonRawBody(), but i'm wondering why the behaviour? (I used phalcon 3.* for another project and it worked just fine)
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
