首先,对不起我的英语......我会尝试以更好的方式表达。
我正在使用 JMSSerializerBundle 在 Symfony 2.7 中构建 API Rest。我有一个地址属性分开的客户模型:(line1,line2,city,postal_code,state,country_code),当我发送响应时,我正在这样做:
{
"company_name": "Foograde",
"first_name": "Federico",
"last_name": "Balderas Mata",
"email": "federico.balderas@foograde.com.mx",
"address": {
"line1": "Gral. Ortega #223D",
"city": "Celaya",
"state": "Guanajuato",
"postal_code": "38010",
"country_code": "MX"
}}
如您所见,我在地址对象上发送参数:
/**
* Get address
* @VirtualProperty
* @return array
* @SerializedName("address")
*/
public function getAddress()
{
return array(
'line1' => $this->line1,
'line2' => $this->line2,
'line2' => $this->line3,
'city' => $this->city,
'state' => $this->state,
'postal_code' => $this->postal_code,
'country_code' => $this->country_code
);
}
但是现在我要做的是以相同的形式获取请求,使用地址对象并将属性分开以将它们插入数据库。
任何想法?