I'm trying to use FOSRestBundle's request body converter but my current implementation doesn't seem to work.
I am using Symfony2, Propel, AngularJS (it sends data to 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;
}
In result I have empty model object:
Backend\SettingsBundle\Model\DocumentType Object
(
[id:protected] =>
[name:protected] =>
....
)
To check that data comes to server, I modify 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 model field:
Backend\SettingsBundle\Model\DocumentType Object
(
[id:protected] => 2
[name:protected] => 'Oferta'
....
)