Php CodeIgniter REST API调用不存在的方法
使用Phil Sturgeon的,我已经建立了一个基本的REST服务器来与主干应用程序交互。问题在于,每当应用程序尝试向适当的URI发出删除请求时(例如,api/object/7,其中7是有问题的ID号),REST都会返回404 Not Found错误。一点挖掘表明,它试图到达控制器中不存在的7_delete,而不是调用它应该调用的index_delete 我已经检查了请求,它们正在路由到正确的URL;我还检查过,没有设置会干扰的自定义路由,也没有。建议 编辑:有关更多详细信息,主干路由设置如下:Php CodeIgniter REST API调用不存在的方法,php,codeigniter,rest,backbone.js,Php,Codeigniter,Rest,Backbone.js,使用Phil Sturgeon的,我已经建立了一个基本的REST服务器来与主干应用程序交互。问题在于,每当应用程序尝试向适当的URI发出删除请求时(例如,api/object/7,其中7是有问题的ID号),REST都会返回404 Not Found错误。一点挖掘表明,它试图到达控制器中不存在的7_delete,而不是调用它应该调用的index_delete 我已经检查了请求,它们正在路由到正确的URL;我还检查过,没有设置会干扰的自定义路由,也没有。建议 编辑:有关更多详细信息,主干路由设置如下
urlRoot: 'api/objective/',
class Objective extends REST_Controller {
/**
* Respond to a POST request;
* - If given an ID, update an existing record
* - If given no ID, create a new record
*/
public function index_post() {
// code here...
}
/**
* Delete an existing record from a passed URL
*/
public function index_delete($id) {
// Code here...
}
/**
* Get a single record
*/
public function index_get($id) {
// Code here...
}
/**
* Get the full objectives list
*/
public function index_get() {
// Code here...
}
}
CI中的目标控制器设置如下:
urlRoot: 'api/objective/',
class Objective extends REST_Controller {
/**
* Respond to a POST request;
* - If given an ID, update an existing record
* - If given no ID, create a new record
*/
public function index_post() {
// code here...
}
/**
* Delete an existing record from a passed URL
*/
public function index_delete($id) {
// Code here...
}
/**
* Get a single record
*/
public function index_get($id) {
// Code here...
}
/**
* Get the full objectives list
*/
public function index_get() {
// Code here...
}
}
这与原始示例文件中提供的示例非常接近。但是,CI路由没有设置。如果您使用这样的url,可能会很容易
你能提供一些详细的代码吗?@moberemk你是如何在CI&Backbone中设置路由的?我在上面的帖子中添加了一些细节来回答你的问题。问题是,它完全否定了使用REST API的意义,因为它没有使用DELETE方法而不是简单的GET URL。不过还是不错的尝试。