backbone.js DELETE 请求和 codeigniter Restserver 的问题 (phils)
我确信这是我做错的事情,但我似乎无法弄清楚。我正在使用backbone.js 与我的休息服务器(Philip Sturgeon 的codeigniter Restserver)对话。我正在我的骨干集合模型之一上运行正常的 model.destroy() 。
//a basic example
tagCollection.at(5).destroy();
这会创建对 url 的正确调用,例如:
DELETE http://mydomain.com/ index.php/tags/tag/id/12
当我进入“tag_delete”php函数并执行以下操作时:
$this->delete('id');
这总是不返回任何内容。我认为这与backbone.js 发送请求的方式有关,但我没有发现任何问题。详细信息如下。
Backbone 正在发出“DELETE”请求。
我的 REST_Controller 方法中的相关代码:
function tag_delete () {
//delete the tag
$id = $this->delete('id'); //always empty
$result = $this->tag_model->delete($id);
if (! $result) {
$this->response(array('status' => 'failed'), 400);
}
$this->response(array('status' => 'success'), 200);
}
有什么想法吗?任何backbone.js专家在使用codeigniter和Philip Sturgeon的restserver时遇到过这个问题吗?
I'm sure this is something I'm doing wrong, but I can't seem to figure it out. I'm using backbone.js to talk to my rest server (Philip Sturgeon's codeigniter restserver). I am running a normal model.destroy() on one of my backbone collections model.
//a basic example
tagCollection.at(5).destroy();
This creates a proper call to a url like:
DELETE http://mydomain.com/index.php/tags/tag/id/12
When I get inside my "tag_delete" php function, and do:
$this->delete('id');
This always returns nothing. I assume this has something to do with the way backbone.js sends it's requests, but nothing is jumping out at me. Details below.
Backbone is issuing a "DELETE" request.
Relevant code from my REST_Controller method:
function tag_delete () {
//delete the tag
$id = $this->delete('id'); //always empty
$result = $this->tag_model->delete($id);
if (! $result) {
$this->response(array('status' => 'failed'), 400);
}
$this->response(array('status' => 'success'), 200);
}
Any ideas? Any backbone.js experts run into this when using codeigniter and Philip Sturgeon's restserver?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该是修复删除请求的一种廉价快速方法...
但是,这就是我使用主干和 REST_Controller 组合构建请求的方式...
DELETE http://example.com/index.php/tags/12
(去掉网址的 /tag/id/ 段...它是暗示您要从'tags' 按 id 收集,附加 /tag/id 是不必要的)
对于集合:
然后将类似的内容添加到您的路由中:
这将设置 Restserver 控制器所需的结构......这样更易于管理如果您正在做大量的 Backbone 工作。
This should be a cheap quick way to fix your delete request...
However, this is how I am structuring my requests using a combo of backbone and REST_Controller...
DELETE http://example.com/index.php/tags/12
(get rid of the /tag/id/ segment of the url... it's implied that you are deleting a 'tag' row from the 'tags' collection by id, appending /tag/id is unnecessary)
for the collection:
Then add something like this to your routes:
which will set up the structure necessary for the restserver controller... it is just much more manageable that way if you are doing a lot of Backbone work.
根据 tgriesser 的建议,最好的方法是使用集合上的 url 属性。我之前使用过以下内容,它的工作原理就像魅力(以下控制器使用 silex 框架 + paris 库实现用于数据访问):
在您的主干集合中,添加以下内容:
最近,我写了一篇关于如何执行 GET/POST 的教程/PUT/DELETE 使用 Backbone.js 和 PHP http://cambridgesoftware.co .uk/blog/item/59-backbonejs-%20-php-with-silex-microframework-%20-mysql,可能会有所帮助。
As per tgriesser's suggestion, the best way to do this is to use the url property on the collection. I have used the following before and it works like charm (the following controller implemented using silex framework + paris library for data access):
In your backbone collection, add the following:
Recently, I have written a tutorial on how to do GET/POST/PUT/DELETE with Backbone.js and PHP http://cambridgesoftware.co.uk/blog/item/59-backbonejs-%20-php-with-silex-microframework-%20-mysql, might be helpful.