Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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



83.0k

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

Reading http://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



4.1k
Accepted
answer

or:

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

Thanks boston! It works! Carlos

edited Apr '16

or:

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

There is also $request->getJsonRawBody()