因此,我想创建一些登录页面,然后在登录成功后在仪表板上显示用户名。但是名称不会显示在仪表板上。它只是空白。没有错误通知之类的。请帮忙。谢谢
我在PHP 7上运行
Auth.php控制器
public function index()
{
$this->form_validation->set_rules('email','email',
'trim|required|valid_email');
$this->form_validation->set_rules('password','Password','trim|required');
if($this->form_validation->run() == false){
$data['title']='Login Page';
$this->load->view('templates/auth_header', $data);
$this->load->view('auth/login');
$this->load->view('templates/auth_footer');
}
else{
//success validation
$this->_login();
}
}
private function _login()
{
$email = $this->input->post('email');
$password = $this->input->post('password');
$user = $this->db->get_where('user',['email' => $email])->row_array();
if($user){
//user active
if($user['is_active']==1){
//check password
if(password_verify($password, $user['password'])){
//if pass were right
$data = [
'email' => $user['email'],
'role_id' => $user['role_id']
];
$this->session->set_userdata('$data');
redirect('user');
}
else{
$this->session->set_flashdata('message','<div class="alert alert-danger" role="alert"> Wrong password</div>');
redirect('auth');
}
}
else{
//
$this->session->set_flashdata('message','<div class="alert alert-danger" role="alert">
Email has not been activated</div>');
redirect('auth');
}
}
else{
//no email in database
$this->session->set_flashdata('message','<div class="alert alert-danger" role="alert">
Email is not registered</div>');
redirect('auth');
}
}
和用于在页面中显示数据的命令
慕容森