Codeigniter&;HMVC回调首先显示
在我的codeigniter版本3.1.4/hmvc登录时,如果表单验证密码输入出于某种原因为空,回调函数将首先显示,而不是显示所需的消息 如消息所示,它应该首先显示所需密码的消息,而不是回调消息 问题如何确保它显示正确的验证消息 首先 自动加载表单验证Codeigniter&;HMVC回调首先显示,codeigniter,codeigniter-3,hmvc,codeigniter-hmvc,Codeigniter,Codeigniter 3,Hmvc,Codeigniter Hmvc,在我的codeigniter版本3.1.4/hmvc登录时,如果表单验证密码输入出于某种原因为空,回调函数将首先显示,而不是显示所需的消息 如消息所示,它应该首先显示所需密码的消息,而不是回调消息 问题如何确保它显示正确的验证消息 首先 自动加载表单验证 $autoload['libraries'] = array('database', 'form_validation'); 控制器 <?php class Login extends MX_Controller { p
$autoload['libraries'] = array('database', 'form_validation');
控制器
<?php
class Login extends MX_Controller {
public $CI;
public function __construct() {
parent::__construct();
$this->load->model('catalog/user/user_model');
$this->form_validation->CI =& $this;
}
public function index() {
$data['type'] = $this->input->post('type');
$data['password'] = $this->input->post('password');
$this->form_validation->set_rules('type', 'Username Or Email', 'trim|required');
$this->form_validation->set_rules('password', 'password', 'required|callback_validatePassword[password]');
if ($this->form_validation->run() == false) {
$data['header'] = Modules::run('catalog/common/header/index');
$data['footer'] = Modules::run('catalog/common/footer/index');
$this->load->view('template/account/login', $data);
} else {
$user_info = $this->user_model->get_user($user_id = '', $this->input->post('type', true));
if ($user_info) {
$remember = $this->input->post('remember') ? TRUE : FALSE;
$this->user->login($user_info['user_id'], $remember);
redirect(base_url("users") .'/'. $user_info['user_id'] .'/'. $user_info['username']);
}
}
}
public function validatePassword($str) {
if ($this->user_model->validate_password($str, $this->input->post('type', true))) {
return TRUE;
} else {
$this->form_validation->set_message('validatePassword', 'Opp\'s somthing wrong with login!');
return FALSE;
}
}
}
而不是这个-
$this->form_validation->set_rules('password', 'password', 'required|callback_validatePassword[password]');
请像这样使用回调函数-
$this->form_validation->set_rules('password', 'password', 'required', 'callback_validatePassword');
为什么我仍然有同样的问题?你可以做一件事,首先检查post值是否为空?如果(!empty($data['password']){$this->form_validation->set_rules('password','password','callback_validatePassword[password]');}
$this->form_validation->set_rules('password', 'password', 'required|callback_validatePassword[password]');
$this->form_validation->set_rules('password', 'password', 'required', 'callback_validatePassword');