CodeIgniter Forums
Is it Bug or feature, having variables from parent view - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Is it Bug or feature, having variables from parent view (/showthread.php?tid=14493)



Is it Bug or feature, having variables from parent view - El Forum - 01-05-2009

[eluser]fuksito[/eluser]
I found that in the view loaded from another view there is also variables from parent view. I don't want they to be there.


Is it Bug or feature, having variables from parent view - El Forum - 01-05-2009

[eluser]xwero[/eluser]
It's a feature. It allows you to do
Code:
$this->load->vars(array('site_name'=>'My site'));
$this->load->view('header');
// ...
$this->load->view('footer');
// the same without the vars method
$data['site_name'] = 'My site';
$this->load->view('header',$data);
// ...
$this->load->view('footer');
And in the view files you just echo $site_name without binding the variable to each view.

If you want to change this behavior you need to overwrite the _ci_load method of the loader class.


Is it Bug or feature, having variables from parent view - El Forum - 01-05-2009

[eluser]Chris Williams[/eluser]
That's clever! I didn't think of that.


Is it Bug or feature, having variables from parent view - El Forum - 10-25-2009

[eluser]fuksito[/eluser]
Dont you know if there are allready writed ?