我正在使用Ion Auth进行身份验证,并且很难返回验证错误。 login();
函数按预期返回它们,并且在运行register();
时,我被正确重定向,但不会返回任何错误。
表单验证:
$this->load->library('form_validation', array(), 'register_form');
$this->register_form->set_rules('first_name', $this->lang->line('create_user_validation_fname_label'), 'required|xss_clean');
$this->register_form->set_rules('last_name', $this->lang->line('create_user_validation_lname_label'), 'required|xss_clean');
$this->register_form->set_rules('email', $this->lang->line('create_user_validation_email_label'), 'required|valid_email');
$this->register_form->set_rules('phone', $this->lang->line('create_user_validation_phone_label'), 'required|xss_clean');
$this->register_form->set_rules('company', $this->lang->line('create_user_validation_company_label'), 'required|xss_clean');
$this->register_form->set_rules('password', $this->lang->line('create_user_validation_password_label'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$this->register_form->set_rules('password_confirm', $this->lang->line('create_user_validation_password_confirm_label'), 'required');
注册:
if($this->register_form->run() == true){
$username = strtolower($this->input->post('first_name')) . ' ' . strtolower($this->input->post('last_name'));
$email = $this->input->post('email');
$password = $this->input->post('password');
$additional_data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'company' => $this->input->post('company'),
'phone' => $this->input->post('phone'),
);
if($this->ion_auth->register($username, $password, $email, $additional_data)){
$this->ion_auth->set_message_delimiters('','');
$this->session->set_flashdata('register_message', $this->ion_auth->messages());
redirect('home/index', 'refresh');
}else{
$this->ion_auth->set_error_delimiters('','');
$this->session->set_flashdata('register_error', $this->ion_auth->errors());
redirect('home/index', 'refresh');
}
}
这就是我将flash数据传递给我的观点的方式:
$this->data['register_message'] = $this->session->flashdata('register_message');
$this->data['register_error'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('register_error');
在我的视图中回显$register_error
时,我没有得到任何内容,在运行print_r($this->session->all_userdata());
后使用register();
打印会话对象时,user_data
数组为空。我正在使用空字段运行register();
,因此应该有错误。有什么建议吗?
答案 0 :(得分:0)
CodeIgniter“flashdata”,仅适用于下一台服务器 请求,然后自动清除。
这就是为什么你在会话数据中找不到它。 您可以通过额外的keep_flashdata请求保留flashdata变量。
$this->session->keep_flashdata('item');
此行中有右括号错误。
$this->data['register_error'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('register_error');
将其更改为
$this->data['register_error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('register_error'));