Welcome Guest, Not a member yet? Register   Sign In
Views and passed variable scopes
#15

(02-06-2017, 12:29 PM)polarthedog Wrote: The troubling part is the way it holds nested info.
What I find troubling is a situation where I might be repeatedly loading views and data loaded earlier sticks around:
PHP Code:
public function somemethod() {
        
$foo = array(
            
"val1" => "one",
            
"val2" => "two",
            
"val3" => "three"
        
);
        
$this->load->view("testview"$foo);
        
        
$bar = array(
            
"val1" => "changed one",
            
"val2" => "changed two"
        
);
        
$this->load->view("testview"$bar);
    } 
When I load the view the second time with $bar--an entirely different data array-- then $val3 from $foo which was used the first time is defined. Here's a sample testview.php:
PHP Code:
<?php
/**
 * view to test scope when loading views in CI
 */
?>
<div>val1=<?php echo $val1?></div>
<div>val2=<?php echo $val2?></div>
<div>val3=<?php echo $val3?></div> 
And here's the output:
Code:
val1=one
val2=two
val3=three
val1=changed one
val2=changed two
val3=three

If I load a view and specify some entirely different data array, I would expect that only the keys in that array get expanded into vars within the view.
Reply


Messages In This Thread
RE: Views and passed variable scopes - by Narf - 04-15-2016, 07:50 AM
RE: Views and passed variable scopes - by Narf - 04-15-2016, 09:19 AM
RE: Views and passed variable scopes - by Narf - 04-15-2016, 09:36 AM
RE: Views and passed variable scopes - by Narf - 04-15-2016, 09:49 AM
RE: Views and passed variable scopes - by Narf - 04-22-2016, 03:32 PM
RE: Views and passed variable scopes - by sneakyimp - 07-12-2017, 05:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB