Dmi*_*bin 6 propel symfony fosrestbundle
我正在尝试使用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 }
Run Code Online (Sandbox Code Playgroud)
方法:
/**
* @View()
* @Put("/documenttypes")
* @ParamConverter("documentType", converter="fos_rest.request_body")
*/
public function putAction(DocumentType $documentType)
{
print_r($documentType);
return $documentType;
}
Run Code Online (Sandbox Code Playgroud)
结果我有空模型对象:
Backend\SettingsBundle\Model\DocumentType Object
(
[id:protected] =>
[name:protected] =>
....
)
Run Code Online (Sandbox Code Playgroud)
要检查数据是否到达服务器,我修改方法:
public function putAction(DocumentType $documentType)
{
$content = $this->get("request")->getContent();
$documentType->fromArray(json_decode($content, true));
print_r($documentType);
return $documentType;
}
Run Code Online (Sandbox Code Playgroud)
此方法适用于填充模型字段:
Backend\SettingsBundle\Model\DocumentType Object
(
[id:protected] => 2
[name:protected] => 'Oferta'
....
)
Run Code Online (Sandbox Code Playgroud)
Symfony 抱怨您需要启用fos_rest.converter.request_body服务。
在您的fos_rest配置部分中,config.yml您需要启用body_converter功能:
fos_rest:
body_converter:
enabled: true
Run Code Online (Sandbox Code Playgroud)
现在,如果您列出您的服务,您会注意到该服务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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3240 次 |
| 最近记录: |