[eluser]Unknown[/eluser]
I have a controller that sends an email, then loads a view:
$data['title'] = 'Contact Us';
Code:
$email_data = array('message' => 'This is the message';
$email_message = $this->load->view('email_template', $email_data, TRUE);
// send email...
// if there was a problem store error message in $data['message']
$this->load->view('contact', $data);
And in my view (contact.php):
Code:
<?php if(!empty($message)) : ?>
<?= $message ?>
<?php endif; ?>
Even if there's no problem sending the email, the
variable is not empty -- it contains the email message that's passed to the email template.
So, even though the
array that we're explicitly passing to the view we want to load doesn't contain an index/value for
, since there's a different array that does, and is passed to a different view, that variable is then available in a view to which we're not explicitly passing that array.
I realize that a really simple work around is to initialize any indexes of our "final" $data array that may possibly exist in any other $not_data arrays passed to views that may be loaded before loading our "final" view. But should I have to do this? Is this the intended behavior?
Thanks!