2013-09-22 44 views
2

我正在使用backbone和CodeIgniter Rest服务器, 来自主干网的帖子和获取请求正常工作 但put和delete请求者获得了404错误, “状态”:假的,“错误”:“未知的方法。”}带Backbone,DELETE和PUT请求的CodeIgniter Rest服务器返回404

编辑:我改变了源代码,看看哪种方法笨试图运行 我控制器网址是

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; 
} 
} 
+0

可能重复[在PHP中处理PUT/DELETE参数](http://stackoverflow.com/questions/2081894/handling-put-delete-arguments-in-php) –

+0

不一样的图书馆,我使用https://github.com/philsturgeon/codeigniter-restserver – Idob

+0

我碰到了完全相同的问题;发送PUT到“Interview/{id}”调用方法“13_put ()“而不是”index_put(13)“...... –

回答

3

我有同样的问题。因此,这不是一个错误 - https://github.com/philsturgeon/codeigniter-restserver/issues/255 - 您必须明确指定“index”作为函数(“Interview/index/{id}”),或者给方法一个名称(“rest_put($ id)”,所以访问/休息/ {id}“)

+0

这是非常重要的,因为控制器必须知道调用哪个方法 - 它在接收期望方法名称的参数。使用['_remap'](http://ellislab.com/codeigniter/user-g uide/general/controllers.html#remapping)并根据自定义逻辑路由到您期望的方法。 – swatkins

相关问题