Backbone.js PUT/DELETE problems with Codeigniter R

2020-07-30 02:37发布

问题:

NOTE: This question is related to CodeIgniter-RestServer

When I call model.save() from backbone the function where the put request is routed doesn't gets any PUT data. Firebug shows right PUT parameters being sent. However $this->put('keyname') always returns false. Which means CI's REST Server can't find PUT data as it should.

On the other hand, If I set:

Backbone.emulateJSON = true;  

I can work, as then Backbone will send all PUT data under a single attribute named "model", using this way $this->put('model'); works

Then the extra effor involved is:

$data = json_decode($this->put('model'),true); // to get normal behavior #sucks

回答1:

I was running into this issue as well and pushed a few changes that fix the problem: https://github.com/philsturgeon/codeigniter-restserver/pull/84



回答2:

have been through this problem already in the past. Solution to this problem is to use this inside your functions:

$data = $this->request->body;
echo $data['id'];

Hope that solves it. Cheers!