我是codeigniter的新手,并拥有以下代码:
$userAuthenticated = $this->Membership_model->userLogin($email, $pass);
在模型中,以下是方法:
function userLogin($email, $password)
{
$this->db->select('*');
$this->db->from('members');
$this->db->where('email', $email);
$this->db->where('password', $password);
$query = $this->db->get();
return $query->result();
}
我在访问上面显示的$ userAuthenticated时遇到问题。它包含尝试登录的用户的详细信息。如何访问属性?
此致
答案 0 :(得分:0)
return $query->row();
if($userAuthenticated ){
login true
}else{
login false
}
答案 1 :(得分:0)
我会检查查询选择的行数,如下所示:
if($userAuthenticated->num_rows() > 0){
login
}else{
not login
}
否则你必须进行循环才能选择数据:
foreach($userAuthenticated as $user){
echo $user->[variable];
}
答案 2 :(得分:0)
替换此
return $query->result();
用这个:
if ( $query->num_rows() == 1 ) {
return $query->row(); }
else { return FALSE; }
替换此
$userAuthenticated = $this->Membership_model->userLogin($email, $pass);
用这个
// check negative condition first
if( ! $data['userAuthenticated'] = $this->Membership_model->userLogin($email, $pass) ){
// show no results view
$this->load->view( 'wedontknowyouatall', $data );
}
else {
// we have a result back
// and we have already passed userAuthenticated into $data
// now show result view
$this->load->view( 'mysweetviewpage', $data );
}
在视图页面中,您现在可以访问所有数据库字段,例如
echo $userAuthenticated->email ;
答案 3 :(得分:0)
只需使用
$ userAuthenticated->姓名; $ userAuthenticated->电子邮件; $ userAuthenticated->通;
等等。