I am in the process of creating an activation email for my registration process. I need to pass the variables containing the activation code and email address from my model back to my controller where I will send the email.
My registration form currently writes all signup data to the database and creates and activation code.
How can you pass the variables ‘activation_code’ and ’email’ from my model back to my controller for use in my email.
Model:
...
$new_member_insert_data = array(
'first_name' => $first_name,
'last_name' => $last_name,
'email_address' => $email,
'password' => hashPassword($salt, $password, $hash),
'activation_code' => activationCode($email, $hash.$salt),
'hash' => $hash
);
$insert = $this->db->insert('members', $new_member_insert_data);
return $insert;
}
Controller
$this->load->model('members_model');
if($this->members_model->create_member())//return variables here somehow
{
//get activation code + email variables
//send activation email
$this->session->set_flashdata('success', 'success');
redirect('home', 'location');
}
else
{
$viewdata['main_content'] = $category;
$this->load->view('includes/template', $viewdata);
}
You could simply return the array of values on success, or FALSE on failure:
…but it doesn’t really make sense, as you must be passing something to the model’s method in order for it to be useful (or have access to some of these values beforehand, your given code is incomplete). Also, it can be confusing returning different data types and usually a bad idea.
Despite not having access to your full code here, I think the safest and most accurate way may be running another query after the
INSERTruns. For instance, looking up the user byemail_address(assuming it’s supposed to be unique).