任何人都可以看到我失踪?Codeigniter回调失败
我正在使用Codeigniter v1.72。
在DOC:
http://codeigniter.com/user_guide/libraries/form_validation.html
它指出:
$这 - > form_validation-> set_rules( '用户名', '用户名', 'callback_username_check');
function username_check($str)
{
if ($str == 'test')
{
$this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
return FALSE;
}
else
{
return TRUE;
}
}
在我班上用户扩展控制器
我在功能寄存器:
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean', 'callback_username_check('.$username.')');
I have also tried
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean', 'callback_username_check');
而且
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean', 'callback_username_check['.$username.']');
function username_check($str)
{
$this->load->model('User_model', '', TRUE);
$taken = $this->User_model->countUsername($str);
if($taken)
{
$this->form_validation->set_message('username_check', 'That username is already taken');
return FALSE;
}
else
return TRUE;
}
有没有错误可言,没有我的方式工作,代码的行为就像它不在那里。
我看不到你可以在哪里添加回调函数。 – helle 2010-11-06 22:39:48
@helle:该函数是一个回调函数。如果你阅读他引用的网页,你会看到'callback_username_check'设置'username_check'为回调。 – 2010-11-06 22:45:00