使用钩子在 codeigniter Ion auth 中激活用户后发送电子邮件
Send Email after user activation in codeigniter Ion auth using hook
我在我的项目中使用 Ion Auth,我想在用户激活后向用户发送欢迎电子邮件 his/her email.I 知道我可以使用 post_activate_successful hook 但我的 hook 文件中需要用户 ID,所以我不知道如何在 hook 中传递该 ID。
config/hooks.php
$hook['post_activate_successful'][] = array(
"class" => "Welcom_email",// any name of class that you want
"function" => "index",// a method of class
"filename" => "Welcom_email.php",// where the class declared
"filepath" => "hooks"// this is location inside application folder
);
hooks/Welcome_email.php
class Welcom_email
{
public function index()
{
$this->load->library('email');
//$id variable is not defined here so how can I pass that variable hook
$user = $this->ion_auth_model->user($id)->row();
$message = $this->load->view('auth/email/welcome_email',null, true);
$this->email->clear();
$this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->to($user->email);
$this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_activation_subject'));
$this->email->message($message);
$this->email->send();
}
}
我认为您应该简单地将用户 ID 存储在会话变量中,然后在发送电子邮件后再次取消设置会话变量。应用程序中的每个地方都可以访问会话变量
我在我的项目中使用 Ion Auth,我想在用户激活后向用户发送欢迎电子邮件 his/her email.I 知道我可以使用 post_activate_successful hook 但我的 hook 文件中需要用户 ID,所以我不知道如何在 hook 中传递该 ID。
config/hooks.php
$hook['post_activate_successful'][] = array(
"class" => "Welcom_email",// any name of class that you want
"function" => "index",// a method of class
"filename" => "Welcom_email.php",// where the class declared
"filepath" => "hooks"// this is location inside application folder
);
hooks/Welcome_email.php
class Welcom_email
{
public function index()
{
$this->load->library('email');
//$id variable is not defined here so how can I pass that variable hook
$user = $this->ion_auth_model->user($id)->row();
$message = $this->load->view('auth/email/welcome_email',null, true);
$this->email->clear();
$this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->to($user->email);
$this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_activation_subject'));
$this->email->message($message);
$this->email->send();
}
}
我认为您应该简单地将用户 ID 存储在会话变量中,然后在发送电子邮件后再次取消设置会话变量。应用程序中的每个地方都可以访问会话变量