Validation of data in Codeigniter

1
  

Controller

    public function update($id){
     $method = $_SERVER['REQUEST_METHOD'];
    if($method != 'PUT' || $this->uri->segment(3) == '' || is_numeric($this->uri->segment(3)) == FALSE){
        json_output(400,array('status' => 400,'message' => 'Bad request.'));
    } else {
        $params = json_decode(file_get_contents('php://input'), TRUE);
        if($params['name'] == "" || $params['lastname'] == "" || $params['password'] == "" || $params['mobile'] == ""){
            $respStatus = 400;
            $response = array('status' => 400,'message' => 'Hay datos que no deben ser vacios','data'=> $params);
        } else {
            $this->load->model('Usermodel');
            $response = $this->Usermodel->edit($id,$params);
        }
        json_output($respStatus,$response);

    }
}
  

Model

public function edit($id,$data){
        $this->db->trans_start();
        $this->db->where('id',$id)->update('usuario',$data);
        if($this->db->trans_status() == FALSE){
            $this->db->trans_rollback();
            return array('status' => 500,'message' => 'Internal server error.');
        } else {
            $this->db->trans_commit();
            return array('status' => 200,'message' => 'Datos actualizados');
        }

    }

My problem is that it always sends me to error 400 "There are data that should not be empty", I am sending with postman for the tests. I do not know if the validation is doing it correctly, as you can see in the driver I print by json $ params which throws me null

    
asked by DoubleM 16.03.2018 в 23:53
source

0 answers