我尝试在登录后显示用户的名字,但它没有出现在页面上。我尝试这样显示它
<h2> Welcome <?php echo $this->session->userdata('firstname'); ?> </h2>
但是它没有显示用户的名字,尽管DB中有数据.但是当我尝试将'firstname'
更改为'username'
时,它显示了用户的电子邮件(test@gmail.com).我如何显示用户的名字?下面是我的控制器:
function login(){
$this->form_validation->set_rules('username', 'Username', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE) {
redirect('/');
} else {
$user_login = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password'),
);
$login = new UI_model;
$result = $login->login_user($user_login);
if($result){
$auth_details = array(
'firstname' => $result->firstname,
'lastname' => $result->lastname,
'username' => $result->username,
);
$this->session->set_userdata($auth_details);
// $this->session->set_userdata('authenticated', '1');
$this->session->set_flashdata('status', 'User Logged in Successfully!');
redirect(base_url('pages/index'));
} else {
$this->session->set_flashdata('status', 'Invalid Credentials. Please try again');
redirect(base_url('pages/about'));
}
}
}
以下是我的模型:
public function login_user($data){
$this->db->select('*');
$this->db->where('username', $data['username']);
$this->db->where('password', $data['password']);
$this->db->from('users');
$this->db->limit(1);
$query = $this->db->get();
if($query->num_rows() == 1){
return $query->row();
} else {
return false;
}
}
1条答案
按热度按时间kyks70gy1#
您是否可以附加正在使用的数据库的映像并回显所有数据会话?