【发布时间】: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