在我看来,我想要做的是在用户成功注册后清除表单字段。这里一切正常,即用户正在注册,成功消息正在显示给用户,除了我想要做的是清除表单字段的值,我正在使用它
// Clear the form validation field data, so that it doesn't show up in the forms
$this->form_validation->_field_data = array();
在我添加这个之后,CI 一直给我这个错误:致命错误:无法访问受保护的属性 CI_Form_validation::$_field_data in
C:\wamp\www\CodeIgniter\application\controllers\user.php 在第 92 行
这是相关的控制器代码:
public function signup()
{
// If the user is logged in, don't allow him to view this page.
if (($this->_isLoggedIn()) === true) {
$this->dashboard();
}
else
{
$data['page'] = 'signup';
$data['heading'] = 'Register yourself';
$data['message'] = $this->_regmsg;
$this->load->library('form_validation');
// $this->form_validation->set_rules('is_unique', 'Sorry! This %s has already been taken. Please chose a different one.');
$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]|is_unique[users.username]|callback_valid_username');
$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');
// run will return true if and only if we have applied some rule all the rules and all of them are satisfied
if ($this->form_validation->run() == false) {
$data['errors'] = isset($_POST['submit']) ? true : false;
$data['success'] = false;
$this->_load_signup_page($data);
}
else{
if($this->users->register_user($_POST)){
$data['errors'] = false;
$data['success'] = true;
// Clear the form validation field data, so that it doesn't show up in the forms
$this->form_validation->_field_data = array();
$this->_load_signup_page($data);
}
}
}
}
private _load_signup_page($data){
$this->load->view('template/main_template_head');
$this->load->view('template/blue_unit', $data);
$this->load->view('signup', $data);
$this->load->view('template/main_template_foot');
}
谁能告诉我这条线是怎么回事?
$this->form_validation->_field_data = array();
PS:这是我在表单中显示值的方式:
<?php echo set_value('fieldname'); ?>