我在CI应用程序中使用form_validation
并在callback function
中使用set_rules()
时出错:
无法访问与您的字段名称对应的错误消息 电子邮件(validate_credentials)
我的控制器代码是:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Auth extends MX_Controller
{
// public function __construct()
// {
// parent::__construct();
// }
// public function index()
// {
// $this->load->view('auth/login_v');
// }
public function login()
{
$this->load->view('auth/login_v');
}
public function login_validation()
{
//$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'required|trim|callback_validate_credentials');
$this->form_validation->set_rules('password', 'Password', 'required|md5|trim');
if($this->form_validation->run())
{
redirect('dashboard');
} else {
$this->load->view('auth/login_v');
}
//echo $this->input->post('email');
}
public function validate_credentials()
{
$this->load->model('Auth_model');
if($this->Auth_model->can_log_in())
{
return true;
} else {
$this->form_validation->set_message('validate_credentials', 'Incorrect Email/Password');
return false;
}
}
}
我不知道我在哪里误会。 我已将参数传递给tha回调函数:
$this->form_validation->set_rules('email', 'Email', 'required|trim|callback_validate_credentials[email]');
和
public function validate_credentials($email)
{
$this->load->model('Auth_model');
但我得到同样的错误。
我推荐了以下网站:
In Codeigniter, how to pass a third parameter to a callback (form validation)?
Unable to access an error message corresponding to your field name
Callback function in Codeigniter with multiple parameters during form validation
CodeIgniter callback functions with parameters
Callback Function Error ( Unable to access an error message corresponding to your field name )
我正在为我的应用程序使用codeigniter 3.1.6和HMVC。
任何形式的帮助都会受到欢迎。感谢