0

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);
                    }

1 Answer 1

1

You could simply return the array of values on success, or FALSE on failure:

$insert = $this->db->insert('members', $new_member_insert_data);
if ($insert) {
    return $new_member_insert_data; // Same data
}
else {
    return FALSE;
}

...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 INSERT runs. For instance, looking up the user by email_address (assuming it's supposed to be unique).

Sign up to request clarification or add additional context in comments.

1 Comment

I followed your advice and ran a second function looking up the user by email address and getting the activation code. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.