vinn vinn - 1 year ago 75
PHP Question

codeigniter restful api yielding null value with status code 400 in PUT operations

I cant be able to carry PUT operations on my codeigniter restful api app due to status code 400.

Here is the controller:

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);
}
}
}

Answer Source

I realized that PUT method is not working with me. Using POST method instead saved my day.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download