Question

I have an issue with my ZF2 based application and Backbone at frontend. Somewhere at frontent I run

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() )
});

I turn on my Chrome sniffer and see the request details:

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

And request payload is:

{"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 used to handle this request runs appropriate action:

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

My trouble is that I see in result this:

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) ""
}

Here we see that id parsed good, but all data fall into key of some strange array. Now I am retrieving data from this key, but guess this is bad way. Could anybody help me to figure out how to make controller parse data appropriate.

UPDATE

Well it seems the solution is just to update ZF2 to 2.2 stable version.

Was it helpful?

Solution

Question is solved. If you face the same trouble just update your ZF2 to 2.2 stable version or later.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top