douyu0852 2013-05-27 19:45
浏览 71

CodeIgniter REST API调用不存在的方法

Using Phil Sturgeon's Codeigniter REST SERVER, I've set up a basic REST server to interact with a Backbone application. The issue is that whenever the applcation tries to make a DELETE request to the proper URI (for instance, api/object/7 where 7 is the ID number in question), REST returns a 404 Not Found error. A bit of digging revealed that it was trying to reach the nonexistint 7_delete within the controller instead of calling index_delete as it should.

I've checked the requests, and they're routing to the correct URL; I've also checked that there are no custom routes set up which would interfere and there are none. Suggestions?

EDIT: For more detail, the Backbone routing is set up like this:

urlRoot: 'api/objective/',

The Objective controller in CI meanwhile is set up like this:

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...
  }
}

This is close to the example provided in the original example file. The CI routing has nothing set up however.

  • 写回答

1条回答 默认 最新

  • dongxingchang9345 2013-09-13 19:59
    关注

    maybe it easy when you use url like this http://example.com/api/objective/deletecontent/id/7

        public function deletecontent_get() {
            if(!$this->get('id')) {$this->response(null,400)}
              $run = $this->some_model->delete_content_by_id($this->get('id));
              if($run) $this->response(true,200);
              else $this->response(null,304);
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器