我需要通过会话(id)进行预约。
我的模特:
public function get_all($id=NULL){
if ($id != NULL):
$id = $this->session->userdata($id);
$this->db->where('id_user', $id);
$this->db->like('tipo_user', 'inquilino');
return $this->db->get('users');
endif;
}
我的观点:
$query = $this->sindico->get_all()->result();
我需要向所有属于清算人的居民展示
我的查询的示例:
select * from user where id_user = 1 and tipo_user = "%residents%"
出现执行此错误时:
致命错误:在
中的非对象上调用成员函数result()
答案 0 :(得分:0)
更改为:
public function get_all($id=NULL){
if ($id == NULL):
$id = $this->session->userdata($id);
$this->db->where('id_user', $id);
$this->db->like('tipo_user', 'inquilino');
return $this->db->get('users');
endif;
}
由于您未在视图中传递ID(例如:
$query = $this->sindico->get_all($id)->result();
您正在跳过整个函数,因为如果没有传递参考,则设置$id=NULL
。
这就是为什么它说Call to a member function result() on a non-object in
。
你有2个选择;由于您使用$id=NULL
作为查询的参数,因此您需要在传递else
的时间内添加$id
语句,这样您就需要这样做:
public function get_all($id=NULL){
if ($id == NULL):
$id = $this->session->userdata($id);
$this->db->where('id_user', $id);
$this->db->like('tipo_user', 'inquilino');
return $this->db->get('users');
else:
$this->db->where('id_user', $id);
$this->db->like('tipo_user', 'inquilino');
return $this->db->get('users');
endif;
}
如果您永远不会传递$id
作为参考,那么您可以删除整个if语句并执行:
public function get_all(){
$id = $this->session->userdata($id);
$this->db->where('id_user', $id);
$this->db->like('tipo_user', 'inquilino');
return $this->db->get('users');
}