【问题标题】:codeigniter restful api yielding null value with status code 400 in PUT operationscodeigniter restful api 在 PUT 操作中产生具有状态码 400 的空值
【发布时间】:2017-08-17 13:28:57
【问题描述】:

由于状态码 400,我无法在我的 codeigniter restful api 应用程序上执行 PUT 操作。

这里是控制器:

    public function index_put(){
// for put you need to pass id as parameter 

// Use validation library, instead of checking just for value.
$this->load->library('form_validation');
$this->form_validation->set_rules('id','ID','trim|required|integer');
$this->form_validation->set_rules('city','City','trim|required');

if($this->form_validation->run() == FALSE)
{
    // send back list of validation errors.
 $this->response(
 $this->validation_errors(),REST_Controller::HTTP_BAD_REQUEST);
}

$update=$this->cities_model->update($this->post('id'),$this->post('city'));
if(!is_null($update))
{
    $this->response(array('response' => 'content updated 
    successfully'),REST_Controller::HTTP_OK);
   }
  else
 {
 $this->response(array('error'=> 'sorry, technical error occurred, please 
 try again later...'), REST_Controller::HTTP_BAD_REQUEST);
}
}
}

【问题讨论】:

  • 我们将不胜感激。

标签: php rest codeigniter postman


【解决方案1】:

我意识到 PUT 方法 不适用于我。使用 POST 方法 节省了我的时间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-11
    • 2013-11-18
    • 1970-01-01
    • 2016-11-28
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 1970-01-01
    相关资源
    最近更新 更多