We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Post data bug?

$this->request->getPost("name");

doesn't return the post value in a controller. However, I can get the value using:

    parse_str(file_get_contents("php://input"), $data);
    $name = $data["name"];

Why $this->request->getPost("name") doesn't return the correct value? Thanks! Carlos



98.9k

$this->request->getPost("name") gets the value from $_POST['name']



1.4k

Reading https://stackoverflow.com/questions/8893574/php-php-input-vs-post I've realized why $_POST array is empty but I get the correct value using php://input. Could you imporve $this->request->getPost() to include data from php://input ? I've noted \Symfony\Component\HttpFoundation\Request->getContent() uses php://input.

Thanks! Carlos



5.0k
Accepted
answer

or:

$request = new \Phalcon\Http\Request();
$data = json_decode($request->getRawBody());


1.4k

Thanks boston! It works! Carlos

edited Apr '16

or:

$request = new \Phalcon\Http\Request();
$data = json_decode($request->getRawBody());

There is also $request->getJsonRawBody()