Welcome Guest, Not a member yet? Register   Sign In
View data being carried through to the next view?
#1

[eluser]FlashChilli[/eluser]
Hi, I have the code:

Code:
$data['heading'] = 'Pages » New';
$data['class'] = "first";
$this->load->view("core/panel_top.php", $data);
$this->load->view("core/panel_bottom.php");

unset($data);
$this->load->view("core/panel_top.php");
$this->load->view("core/panel_bottom.php");

The first instance of panel_top.php has the variables set, like it should. But for some reason, the second instance of panel_top.php also has these variables set even though I didn't pass it the data array (I even unset the array just in case).

Does codeigniter carry variables through instances of the same views? Is there a way to "clear" these variables as I don't want them to be set in the second view.

Thanks.
#2

[eluser]darkhouse[/eluser]
I would try this:

Code:
$data['heading'] = 'Pages » New';
$data['class'] = "first";
$this->load->view("core/panel_top.php", $data);
$this->load->view("core/panel_bottom.php");

$data = array('heading'=>'', 'class'='');
$this->load->view("core/panel_top.php", $data);
$this->load->view("core/panel_bottom.php");
#3

[eluser]CMCDragonkai[/eluser]
I have the exact same problem except that I cannot redeclare the variables as nothing like what darkhouse said

Code:
$data = array('heading'=>'', 'class'='');
$this->load->view("core/panel_top.php", $data);
$this->load->view("core/panel_bottom.php");

This is because when I pass $data to the the view, it is in a loop and when a new $data is passed the next view, it does not have the same array keys as the previous $data.

I tried unsetting $data in the model, but it still does not work. I tried unsetting the variables in the view, it also does not work.

There must be some way to clear the variables from one view to another.

The specific function I'm trying to do at the moment is to use an attachment_view as a template. I loop through attachment bbcodes and replace each attachment bbcode with their correct html. I'm using $attachment_html = $this->CI->load->view('attachment_view', $data, true); The correct html is located in the attachment_view. There are different kinds of attachments, which means there are different kinds of html to show it. In the attachment_view it uses alot of if-elses to select to correct html.

The problem is, the if-else runs true for the wrong html because the boolean variables carry on from the previous view to the next.




Theme © iAndrew 2016 - Forum software by © MyBB