Welcome Guest, Not a member yet? Register   Sign In
Passing Variables to a load->file call
#1

[eluser]Freewolf[/eluser]
Ok I have a file that I am loading that is being used for generating an email.

Is there a way to pass it variables, and to populate the file with the values of the variables, and THEN plug it into the message body to send?
#2

[eluser]jmb727[/eluser]
Yeah create your email in one view file and your message body in another.

E.g.

Code:
class A_controller extends CI_Controller
{
    public function __construct() {
        parent::__construct();
    }

    public function index() {
        //
    }
    
    public function createEmail($bodyVars)
    {
        $data = array();
        $data['body'] = $this->load->view('email/body', $bodyVars, TRUE);
        $this->load->view('email/layout', $data);
    }
}

In the function $this->load->view('email/body', $bodyVars, TRUE) the third argument is a boolean which determines whether the view file should be returned as a string or not. It defaults to FALSE which means it gets printed to the screen, however set it to TRUE and it will load the data you pass into it (i.e. $bodyVars) and return the view file into a variable.




Theme © iAndrew 2016 - Forum software by © MyBB