我发现其他人遇到同样的问题,但无法找到解决问题的方法。如果使用回调函数登录失败,则不会显示我的错误消息。未显示CodeIgniter回调函数
loginController.php
public function validate_credentials() {
$this->load->model('users_model');
$query = $this->users_model->validate();
if($query)
{
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('/member/homes');
}
else
{
$this->form_validation->set_rules('username', 'Username', 'trim|required|callback_check_username_exists'); //test
$data['lofin_failed'] = 'Wrong usename or password'; // I added this line in the meantime to display an error message.
$this->load->view('header');
$this->load->view('navbar');
$this->load->view('loginForm', $data);
$this->load->view('footer');
}
}
public function check_username_exists()
{
$this->form_validation->set_message('check_username_exists', 'Wrong username or password!!');
return false;
}
users_model.php
public function validate() {
$this->db->where('username', $this->input->post('username'));
$this->db->where('password', md5($this->input->post('password')));
$query = $this->db->get('game_players');
if($query -> num_rows() == 1) { // if we have one match
return true;
}
}
您的回调函数应该有一个参数。尝试将它声明为'check_user_exists(username)' –
*'公共函数check_username_exists($ username)' –
我在函数declarion中添加了'$ username'但它没有帮助。有没有办法看到邮件的内容或为什么不显示? – remyremy