在我的codeigniter登录上。如果用户输入的用户名不正确,则应显示错误用户名或密码错误作为flash-data。如果用户输入的用户名不是存在,则会抛出错误用户名不匹配任何记录。
无法获取表单数据库检查错误以显示正确的方法。我可以登录确定,但只是没有正确的登录闪存数据错误。
如何才能使表单数据库错误正常工作。主codeigniter表单验证是正常的,只是不会抛出我的数据库错误。
public function index() {
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required|trim');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE) {
$this->login();
} else {
if ($this->input->post('username') && $this->input->post('password')) {
// Gets the user information from the database.
$user = $this->user_login_model->get('username', $this->input->post('username'));
if ($user) {
// If User Login Success
if ($this->user_login_model->check_password($this->input->post('password'), $user['password']) == TRUE) {
$this->user->login($user['user_id']);
redirect('admin/dashboard');
} else {
$this->session->set_flashdata('error', 'Username or Password Is Does Not Match Any Records!');
$this->login();
}
}
}
}
}
public function login() {
$this->document->setTitle($this->lang->line('heading_title'));
$data['text_login'] = $this->lang->line('text_login');
$data['text_register'] = $this->lang->line('text_register');
$data['entry_username'] = $this->lang->line('entry_username');
$data['entry_password'] = $this->lang->line('entry_password');
$data['action'] = site_url('admin');
$data['button_login'] = $this->lang->line('button_login');
return $this->load->view('common/login', $data);
}
获取用户模型
/**
* Retrieve a user
*
* @param string where
* @param int value
* @param string user_identification field
*/
public function get($where, $value = FALSE) {
if (!$value) {
$value = $where;
$where = 'user_id';
}
$user = $this->db->where($where, $value)->get($this->table)->row_array();
return $user;
}
答案 0 :(得分:0)
只有在用户被重定向到另一个页面时才会显示Flashdata。 在失败的登录操作中,您只将视图加载到用户的屏幕。尝试改变
$这 - >登录();
到
重定向('控制器/登录&#39); // ofc首先更改控制器名称