"posting json objects to symfony 2" Code Answer


If you want to retrieve data in your controller that's been sent as standard JSON in the request body, you can do something similar to the following:

public function yourAction()
    $params = array();
    $content = $this->get("request")->getContent();
    if (!empty($content))
        $params = json_decode($content, true); // 2nd param to get as array

Now $params will be an array full of your JSON data. Remove the true parameter value in the json_decode() call to get a stdClass object.

By 1'' on November 18 2022

Answers related to “posting json objects to symfony 2”

Only authorized users can answer the search term. Please sign in first, or register a free account.