Welcome Guest, Not a member yet? Register   Sign In
Passing Data to View
#1

[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
Code:
$message
variable is not empty -- it contains the email message that's passed to the email template.

So, even though the
Code:
$data
array that we're explicitly passing to the view we want to load doesn't contain an index/value for
Code:
'message'
, 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!


Messages In This Thread
Passing Data to View - by El Forum - 08-28-2012, 06:51 AM
Passing Data to View - by El Forum - 08-28-2012, 10:38 PM
Passing Data to View - by El Forum - 08-30-2012, 04:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB