Не работает ParamConverter с конвертером "fos_rest.request_body"
Я пытаюсь использовать конвертер тела запроса FOSRestBundle, но моя текущая реализация, похоже, не работает.
Я использую Symfony2, Propel, AngularJS (он отправляет данные на сервер)
Что я делаю неправильно?
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 }
Метод:
/**
* @View()
* @Put("/documenttypes")
* @ParamConverter("documentType", converter="fos_rest.request_body")
*/
public function putAction(DocumentType $documentType)
{
print_r($documentType);
return $documentType;
}
В результате у меня есть пустой объект модели:
Backend\SettingsBundle\Model\DocumentType Object
(
[id:protected] =>
[name:protected] =>
....
)
Чтобы проверить, что данные поступают на сервер, я изменяю метод:
public function putAction(DocumentType $documentType)
{
$content = $this->get("request")->getContent();
$documentType->fromArray(json_decode($content, true));
print_r($documentType);
return $documentType;
}
Этот метод работает и заполняет поле модели:
Backend\SettingsBundle\Model\DocumentType Object
(
[id:protected] => 2
[name:protected] => 'Oferta'
....
)
1 ответ
Symfony жалуется, что вам нужно включить fos_rest.converter.request_body
оказание услуг.
В вашем fos_rest
раздел конфигурации внутри config.yml
вам нужно включить body_converter
особенность:
fos_rest:
body_converter:
enabled: true
Теперь, если вы перечислите свои услуги, вы заметите, что услуга fos_rest.converter.request_body
появился:
user@host:~/symfony-project$ php app/console debug:container | grep fos_rest.converter
fos_rest.converter.request_body FOS\RestBundle\Request\RequestBodyParamConverter