Do not use ParamConverter with the converter "fos_rest.request_body"

I am trying to use the FOSRestBundle body body, but my current implementation is not working.

I use Symfony2, Propel, AngularJS (it sends data to the server)

What am I doing wrong?

config.yml:

fos_rest: routing_loader: default_format: json include_format: false view: view_response_listener: force body_listener: true param_fetcher_listener: true body_converter: enabled: true sensio_framework_extra: view: { annotations: false } router: { annotations: true } request: { converters: true } 

Method:

 /** * @View() * @Put("/documenttypes") * @ParamConverter("documentType", converter="fos_rest.request_body") */ public function putAction(DocumentType $documentType) { print_r($documentType); return $documentType; } 

As a result, I have an empty model object:

 Backend\SettingsBundle\Model\DocumentType Object ( [id:protected] => [name:protected] => .... ) 

To verify that the data is being sent to the server, I change the method:

 public function putAction(DocumentType $documentType) { $content = $this->get("request")->getContent(); $documentType->fromArray(json_decode($content, true)); print_r($documentType); return $documentType; } 

This method works and fills the model field:

 Backend\SettingsBundle\Model\DocumentType Object ( [id:protected] => 2 [name:protected] => 'Oferta' .... ) 
+6
source share
1 answer

Symfony complains that you need to enable the fos_rest.converter.request_body service.

In the fos_rest configuration fos_rest in config.yml you need to enable the body_converter function:

 fos_rest: body_converter: enabled: true 

Now, if you list your services, you will notice that the fos_rest.converter.request_body service fos_rest.converter.request_body appeared:

 user@host :~/symfony-project$ php app/console debug:container | grep fos_rest.converter fos_rest.converter.request_body FOS\RestBundle\Request\RequestBodyParamConverter 
+1
source

All Articles