在codeigniter中通过会话传递电子邮件地址

时间:2018-05-20 00:22:51

标签: php codeigniter

public function registration()
{
    $data = array();
    $userData = array();

    if($this->input->post('regisSubmit')){
        $this->form_validation->set_rules('name', 'Name', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback_email_check');
        $this->form_validation->set_rules('password', 'password', 'required');
        $this->form_validation->set_rules('conf_password', 'confirm password', 'required|matches[password]');

        $userData = array(
            'name' => strip_tags($this->input->post('name')),
            'email' => strip_tags($this->input->post('email')),
            'password' => md5($this->input->post('password')),
            'gender' => $this->input->post('gender'),
            'phone' => strip_tags($this->input->post('phone'))
        );

        if($this->form_validation->run() == true){
            $insert = $this->user->insert($userData);
            if($insert){



                redirect('email');
            }else{
                $data['error_msg'] = 'Some problems occured, please try again.';
            }
        }
    }
    $data['user'] = $userData;
    //load the view
    $this->load->view('users/registration', $data);
}

这是我的注册控制器的功能。我希望将电子邮件地址传递给我的另一个控制器:send_email并使用此代码向用户发送电子邮件。

$this->email->to('user_email');我尝试使用会话功能传递变量但失败了。我该怎么办?

1 个答案:

答案 0 :(得分:1)

希望这会对您有所帮助:

注意: 如果未加载session,则必须加载autoload.php库,并且还要避免md5加密密码,请使用{{1而不是

然后必须在password_hash

之前创建email会话

代码结构应该是这样的

redirect();

if($this->form_validation->run() == true) { $insert = $this->user->insert($userData); if($insert) { $this->session->set_userdata('email',$userData['email']); redirect('email'); }else { $data['error_msg'] = 'Some problems occured, please try again.'; } } 这样的方法中使用会话

send_email

了解更多:https://www.codeigniter.com/user_guide/libraries/sessions.html