模型/控制器在codeigniter中不返回true结果

时间:2018-03-29 09:06:07

标签: codeigniter view model controller return

我试图将数据插入到数据库中。插入查询工作正常,值已插入但控制器始终显示其他结果。

型号代码

// Function to add record in table
public function add($data){
    $this->db->insert('xin_employees', $data);
    if ($this->db->affected_rows() > 0 ) {
        return true;
    } else {
        return false;
    }
}

控制器代码

$data = array(
    'first_name' => $this->input->post('first_name'),

);

$result = $this->Employees_model->add($data);
 if ($result == TRUE) {
 $Return['result'] = $this->lang->line('xin_success_add_employee');

2 个答案:

答案 0 :(得分:1)

型号代码:

 // Function to add record in table
    public function add($data){
       if($this->db->insert('xin_employees', $data)){
            return $this->db->insert_id();
        } else {
            return false;
        }
    }

答案 1 :(得分:0)

你可以试试这个

public Location getLocation(int id ) {
    //some code here

    Location location = (Location) session.get(Location .class, id);
    // id that is being passed here in the sessin.get() method needs to be changed to type `com.nsbm.entity.Location` to resolve this error.

    //some code here
    return location;
}