【发布时间】:2015-08-12 05:28:28
【问题描述】:
我已经检查了我的代码可能出错的所有可能的事情,但它仍然向我显示了这个错误。请帮忙。
Unable to access an error message corresponding to your field name Username.(check_username)
这是我下面的代码:
public function index()
{
if ( ! file_exists(APPPATH.'/views/login.php'))
{
/* Whoops, we don't have a page for that! */
show_404();
}
$this->load->helper('security');
$this->load->library('form_validation'); // Including Validation Library.
$this->form_validation->set_error_delimiters('<div class="error">', '</div>'); // Displaying Errors in Div
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|callback_check_username'); // Validation for Username Field
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean'); // Validation for Password field.
if ($this->form_validation->run() == FALSE) {
$this->load->view('login');
}
function check_username($username)
{
if ($username == 'test') {
$this->form_validation->set_message('check_username','already exists.');
return false;
} else {
return TRUE;
}
}
}
【问题讨论】:
-
你检查我的答案了吗
标签: php codeigniter error-handling