getting the value of the single field output using the codeigniter active record

后端 未结 4 720
你的背包
你的背包 2020-12-16 11:46

the following function is supposed to read the name of the given asset code from the database. but it triggers the error: \"Trying to get property of non-object\"

         


        
4条回答
  •  我在风中等你
    2020-12-16 12:26

    I think it's important to check if the record that satisfies the conditions even exists in the database. Code for the model:

    function sban_name($asset){
        $this->db->select('name');
        $this->db->from('asset_types');
        $this->db->where('code',$asset);
        $row = $this->db->get()->row();
        if (isset($row)) {
            return $row->name;
        } else {
            return false;
        }
    }
    

    Simply call the function from the controller like so:

     $response = $this->model_name->sban_name($asset)
    

提交回复
热议问题