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:
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' .... )
source share