错误:让非对象的性质[复制](Error : get property of non-object

2019-07-17 11:10发布

可能重复:
调用一个成员函数的非对象

我收到此错误:试图让非对象[从产品型号]当我尝试通过输入一个字符串,在这种情况下是“东西”从数据库中获取的ID属性

这是我的模型

   function getRoleId($role_name='')
         {

            $conditions = array('role_name'=> $role_name);
            $this->db->where($conditions);
            $this->db->select('id');
            $query = $this->db->get('roles');       
            $row   = $query->row();
            return $row->id;
         }

控制器($ radioRole这里是=东西),但是当它到达模型就变成别的东西。

$radioRole  = 'something';
$insertData['role_id']            = $this->user_model->getRoleId($radioRole);

UPDATE

print_r($radioRole);
$insertData['role_id']            = $this->user_model->getRoleId($radioRole);

显示$ radioRole这是在这种情况下,“东西”

但是,当它到达user_model,当我做的print_r它显示了别的东西,“买家”,它不甚至显示控制器上完成的print_r。 感觉就像它正在通过书面:O,但我还是不知道:O型

的print_r($查询)

  CI_DB_mysql_result Object ( [conn_id] => Resource id #37 [result_id] => Resource id #64 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 0 [row_data] => )

Answer 1:

where是错误的:

$conditions = array('role_name'=> $role_name);
$this->db->where($conditions);

应该

$conditions = array('role_name', $role_name);
$this->db->where($conditions);

编辑:

如在评论中提到,如果条件是直接的内逗号是必要的where因为这样:

$this->db->where('role_name',$role_name);


文章来源: Error : get property of non-object [duplicate]