【发布时间】:2016-06-26 20:25:29
【问题描述】:
我使用 REST 库为 Phil Sturgeon 开发了一个 REST API, GET 和 POST 请求工作正常, 现在,当我尝试使用 PUT 请求访问传递的参数时,我得到了 null。
class ApiItems extends REST_Controller
{
function __construct() {
//
}
public function items_get(){ // //}
public function items_post(){ // //}
public function items_put()
{
if(!$this->put('id')) //My issue : I can't get the id here
{
$this->response(array('error' => 'Item id is required'), 400);
}
$data = array(
'id' => $this->put('id'),
'code'=> $this->put('code'),
'name' => $this->put('name'),
'quantity' => $this->put('quantity')
);
$this->item_model->update_item($this->put('id'), $data);
$message = array('success' => $id.' Updated!');
$this->response($message, 200);
}
}
我使用 POSTMAN 对其进行了测试,结果如下: POSTMAN PUT Call screenshot
我不明白为什么 $this->get(id) 或 $this->post(id) 工作正常,而不是 $this->put(id) 的情况?
【问题讨论】:
-
它正在工作,我在使用 POSTMAN 填充参数时犯了一个愚蠢的错误,我检查了 form-data 而不是 x-www-form-url-encoded
标签: php codeigniter api rest put