Welcome Guest, Not a member yet? Register   Sign In
How to prevent variables bleeding into subsequent views?
#1

[eluser]rf_dev[/eluser]
Is there a way to "empty" all the variables available to a view?

Ok, let me explain. I'm not entirely sure of the best way to describe this issue. This may well be covered elsewhere in this forum but I may not be using the right terms to find it.

Lets say I call a view like this:

Code:
$html = $this->load->view('foo', array('id'=>1), true);

and then I call another one:

Code:
$htmlb = $this->load->view('bar', array(), true);

Within the 'bar' view there's a conditional part which depends on whether an id is set:

Code:
<?php //foo.php
?>
The ID is: <?php echo $id ?>
// output - The ID is: 1

Code:
<?php //bar.php
if(isset($id)){
        echo 'The ID is still '.$id;
        // output - The ID is still: 1
}
?>

The problem is, '$id" is ALWAYS set even though I didn't pass one in. It appears as a hangover from the previous call to a view, any view. Is there a way to stop that happening, seems like a major flaw to me.

Cheers
Lee


Messages In This Thread
How to prevent variables bleeding into subsequent views? - by El Forum - 09-20-2012, 03:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB