PHP ZF2 - Restful控制器Backbone PUT方法解析不正确

时间:2013-05-13 14:36:52

标签: backbone.js zend-framework2 http-put

我的基于ZF2的应用程序和前端的Backbone存在问题。在某个地方我正在运行

this.model.save({
  city_id: parseInt( this.$el.find( '#city_id' ).val() ),
  from: this.$el.find( '#from' ).val(),
  to: this.$el.find( '#to' ).val(),
  price: parseInt( this.$el.find( '#price' ).val() )
});

我打开Chrome嗅探器并查看请求详情:

PUT /account/trip/2 HTTP/1.1
Host: jamydays.ru
Connection: keep-alive
Content-Length: 186
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://jamydays.ru
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31
Content-Type: application/json
Referer: http://jamydays.ru/account
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: PHPSESSID=pekjbefmi1jn01q5fgm4gu6jk0; _ym_visorc=w

请求有效负载是:

{"from_formatted":"10 маÑ","to_formatted":"19 маÑ","url":"/account/trip","id":2,"city_id":65170,"city":"Baardheere","from":"10-05-2013","to":"19-05-2013","price":500,"is_active":1}

用于处理此请求的Conroller会执行相应的操作:

class TripController extends AbstractRestfulController{
  ...
  public function update( $id, $data ){ var_dump( $id, $data );exit(); }
  ...
}

我的麻烦是我在结果中看到了这个:

string(1) "2"
array(1) {
  ["{"from_formatted":"10_мая","to_formatted":"19_мая","url":"/account/trip","id":2,"city_id":65170,"city":"Baardheere","from":"10-05-2013","to":"19-05-2013","price":500,"is_active":1}"]=>
  string(0) ""
}

这里我们看到id解析得很好,但所有数据都属于某个奇怪数组的键。现在我从这个键中检索数据,但猜测这是不好的方法。任何人都可以帮我弄清楚如何使控制器解析数据合适。

更新

似乎解决方案似乎只是将ZF2更新为2.2稳定版本。

1 个答案:

答案 0 :(得分:0)

问题解决了。如果您遇到同样的问题,只需将ZF2更新为2.2稳定版或更高版本。