简体   繁体   English

Codeigniter REST服务器的Backbone.js PUT / DELETE问题

[英]Backbone.js PUT/DELETE problems with Codeigniter REST server

NOTE: This question is related to CodeIgniter-RestServer 注意:此问题与CodeIgniter-RestServer有关

When I call model.save() from backbone the function where the put request is routed doesn't gets any PUT data. 当我从主干调用model.save()时,路由放置请求的函数不会获取任何PUT数据。 Firebug shows right PUT parameters being sent. Firebug显示正确的PUT参数正在发送。 However $this->put('keyname') always returns false. 但是$ this-> put('keyname')始终返回false。 Which means CI's REST Server can't find PUT data as it should. 这意味着CI的REST服务器找不到应有的PUT数据。

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'); 我可以工作,因为Backbone会使用$ this-> put('model');方式在名为“ model”的单个属性下发送所有PUT数据。 works 作品

Then the extra effor involved is: 那么所涉及的额外影响是:

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

我也遇到了这个问题,并提出了一些解决问题的更改: https : //github.com/philsturgeon/codeigniter-restserver/pull/84

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! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM