【问题标题】:CodeIgniter Rest Server with Backbone, DELETE and PUT requests return 404带有 Backbone、DELETE 和 PUT 请求的 CodeIgniter Rest Server 返回 404
【发布时间】:2013-09-27 12:24:18
【问题描述】:

我正在使用主干和 CodeIgniter Rest Server, 来自主干的帖子和获取请求工作正常 但是 put 和 delete 请求者得到 404 错误,响应为 {"status":false,"error":"Unknown method."}

编辑:我更改了源代码以查看 codeigniter 尝试运行的方法 我的控制器网址是

http://local/host/impacto/index.php/interviews/

put 请求的 url 是

http://localhost/impacto/index.php/interviews/13

codeigniter 运行的函数是 13_put 而不是 input_put

我的控制器

class Interview extends REST_Controller {

function __construct(){

    parent:: __construct();
}

public function index_get(){

    echo "get";
}

public function index_post(){

    echo "post";
}

public function index_put($id){

    echo "update: " . $id;
}

public function index_delete($id){

    echo "delete: " . $id;
}
}

【问题讨论】:

标签: php codeigniter rest backbone.js


【解决方案1】:

我遇到了同样的问题。因此,这不是错误 - https://github.com/philsturgeon/codeigniter-restserver/issues/255 - 您必须公开指定“index”作为函数(“Interview/index/{id}”),或者为您的方法命名(“rest_put($id)” ,所以访问了 Interview/rest/{id}")

【讨论】:

  • 这很重要,因为控制器必须知道要调用哪个方法 - 它正在接收它期望方法名称的参数。您可以随时尝试使用_remap 并根据自定义逻辑路由到您期望的方法。
猜你喜欢
  • 2019-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-16
  • 2023-02-24
  • 1970-01-01
相关资源
最近更新 更多