2016-06-26 71 views
0

我開發了一個REST API,用於Phil Sturgeon, GET和POST請求正常工作, 現在,當我嘗試訪問帶有PUT請求的傳遞參數時,我得到空。Codeigniter Rest API:Put請求沒有通過id

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 PUT Call screenshot

我不明白爲什麼這 - $>得到(ID)或$這個 - >後(ID)工作正常,並沒有$ this-> put(id)的情況?

+0

它的工作,我已經填充時做了一個愚蠢的錯誤POSTMAN的參數,我檢查了表單數據而不是x-www-form-url-encoded – eamon

回答

1

它的工作,我已經填充郵差的參數時,做了一個愚蠢的錯誤,我檢查表單數據,而不是X WWW的形式URL編碼的