0

我正在使用 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');
    }
}

这就是我将闪存数据传递到我的视图的方式:

$this->data['register_message'] = $this->session->flashdata('register_message');
$this->data['register_error'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('register_error');

在我看来,当与 with 相呼应$register_error时,我什么也没有得到,并且当使用print_r($this->session->all_userdata());after running打印会话对象时register();user_data数组是空的。我正在register();使用空字段运行,所以应该有错误。有什么建议么?

4

1 回答 1

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'));
于 2013-06-15T17:42:58.597 回答