![]() |
View Data Issue - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19) +--- Thread: View Data Issue (/showthread.php?tid=66348) Pages:
1
2
|
View Data Issue - mertdogan - 10-12-2016 I found a bug for loading view with second array parameter. I use version 3.1.0. My controller function: public function test(){ $data=array('a'=>'A','b'=>'B'); $this->load->view('test',$data); $data=array(); $data=array('b'=>'B'); $this->load->view('test',$data); } and this is my TEST view file: <?php echo $a.'-'.$b.'|'; If you run this structure; it will generate : A-B|A-B| but it must generate and give us a notice message that $a not defined: A-B|-B| because we don't define $a for second call of view file. I tried unset($data) but issues still continues. I don't know why this happens but it can be a buffer problem or somethink else like this. RE: View Data Issue - dave friend - 10-12-2016 By design the loader caches data passed via $this->load->view('test',$data); So, $a IS defined and remains so between calls to load->view. Try this variation on you test function Code: public function test() This will output A-B1|A-B2| Again, this is by design. Look at the source code. Came as a surprise to me too when I first discovered it. RE: View Data Issue - mertdogan - 10-12-2016 (10-12-2016, 02:16 PM)dave friend Wrote: By design the loader caches data passed via $this->load->view('test',$data); So, $a IS defined and remains so between calls to load->view. Ok man; i know if you change $b, it will output changed value. The bug is; we don't call $a again and it must generate error that; it hasn't set. RE: View Data Issue - dave friend - 10-12-2016 $a was set with the first view load. Data passed to any view is cached and is available to any subsequent views that are loaded. RE: View Data Issue - InsiteFX - 10-12-2016 You can use the below method but that means you will need to set all variables passed in: PHP Code: $this->load->clear_vars(); RE: View Data Issue - ciadmin - 10-12-2016 You raised an issue on github ... it might have been an idea to raise it here first, to find out if it was a bug or not. We use github for bug tracking, not support. RE: View Data Issue - mertdogan - 10-13-2016 (10-12-2016, 06:28 PM)InsiteFX Wrote: You can use the below method but that means you will need to set all variables passed in: I don't know this rule. RE: View Data Issue - mertdogan - 10-13-2016 (10-12-2016, 02:32 PM)dave friend Wrote: $a was set with the first view load. Data passed to any view is cached and is available to any subsequent views that are loaded. I want to ask a question: First model loads view with data. And then model loads another model. Second model loads previous view again with another data without clear. What happens at this time? RE: View Data Issue - Narf - 10-13-2016 (10-13-2016, 01:43 AM)mertdogan Wrote:(10-12-2016, 02:32 PM)dave friend Wrote: $a was set with the first view load. Data passed to any view is cached and is available to any subsequent views that are loaded. All data stays, but the newer pieces overwrite older ones. RE: View Data Issue - mertdogan - 10-13-2016 (10-13-2016, 02:00 AM)Narf Wrote:(10-13-2016, 01:43 AM)mertdogan Wrote:(10-12-2016, 02:32 PM)dave friend Wrote: $a was set with the first view load. Data passed to any view is cached and is available to any subsequent views that are loaded. Hmm. I think there must be a fourth parameter for cache these variables. I have checked previously discussed messages in Github. These caching mechanism is good but user may set this option. May be with config parameter... With this type, it can generate a security hole in complex structures. Of course; i learned why this happens and what i must do if i want to load same view again. Thx |