正如标题所说,我正在使用Codeigniter和phil sturgeon - codeigniter-restserver框架。
我已经按照Nettus上的教程进行操作,除了发送DELETE请求时,一切正常。
代码:
<?php
require(APPPATH.'libraries/REST_Controller.php');
class Client extends REST_Controller{
function user_get()
{
$data = array('returned:'=> $this->get('id'));
$this->response($data);
}
function user_post()
{
$data = array('returned:'=> $this->post('id'));
$this->response($data);
}
function user_put()
{
$data = array('returned:'=> $this->put('id'));
$this->response($data);
}
function user_delete()
{
$data = array('returned from delete:'=> $this->delete('id'));
$this->response($data);
}
}
我正在使用名为HTTP资源测试的FF插件来发送请求但是当我发送带有此URL的DELETE请求时:http://localhost/api/client/user/id/1
,我得到{“从删除返回:”:false}
作为旁注:我找到了这个post并使用'X-HTTP-Method-Override'标头并将其作为帖子请求发送我能够获取ID ,但我喜欢客户端不必添加此标题的方式。
答案 0 :(得分:14)
根据HTTP规范DELETE无法发送参数。它可以包含URL中的内容,因此您可以将其更改为:
public function user_delete($id)
{
$this->response(array(
'returned from delete:' => $id,
));
}
答案 1 :(得分:0)
我的这项工作对我来说有同样的问题
1 - &gt;在REST_Controller.php中将默认的_parse_delete()函数替换为:
protected function _parse_delete()
{
$this->_delete_args = $_DELETE;
$this->request->format and $this->request->body = file_get_contents('php://input');
// Set up out DELETE variables (which shouldn't really exist, but sssh!)
parse_str(file_get_contents('php://input'), $this->_delete_args);
}
这就是全部!不再需要&#34; user_delete( $ id )&#34;&#34;