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

(04-15-2016, 01:13 PM)cartalot Wrote: There are thousands of codeigniter websites that depend on $data being available for implementing templates. This has never been an option that has to be set and its worked the same way in ci 1.7, ci 2, and ci 3. Please do not change this.

CI4 will be fundementally different, so now the time is okay to make the necessary changes, I think we should look ahead and not backward...
Reply
#12

(04-15-2016, 01:13 PM)cartalot Wrote: There are thousands of codeigniter websites that depend on $data being available for implementing templates. This has never been an option that has to be set and its worked the same way in ci 1.7, ci 2, and ci 3. Please do not change this.
I agree with Narf that the vars should not be cached at all -- unless there is some way to optionally cache the variables. The caching behavior in effect now is unexpected and barely documented and raises the possibility of problems for those who don't expect it.

Surely there's a fairly simple way the old behavior can be optionally cached for all views loaded? E.g., we might add some config setting that preserves this behavior in CI4 and have it turned off by default.
Reply
#13

(04-22-2016, 02:56 PM)sneakyimp Wrote:
(04-15-2016, 01:13 PM)cartalot Wrote: There are thousands of codeigniter websites that depend on $data being available for implementing templates. This has never been an option that has to be set and its worked the same way in ci 1.7, ci 2, and ci 3. Please do not change this.
I agree with Narf that the vars should not be cached at all -- unless there is some way to optionally cache the variables. The caching behavior in effect now is unexpected and barely documented and raises the possibility of problems for those who don't expect it.

Surely there's a fairly simple way the old behavior can be optionally cached for all views loaded? E.g., we might add some config setting that preserves this behavior in CI4 and have it turned off by default.

The behavior will change, we were discussing the lower level details.
Reply
#14

I would love to know how to overcome this in CI 2.x - I know I should be upgrading to 3 but too much to do atm.

The troubling part is the way it holds nested info. I use arrays rather than objects, so lets say I am passing $item['title'=> 'name', 'options' => ['one', 'two', 'three']] to the first and the second has no option, guess what, the second inherits the firsts options..
Reply
#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




Theme © iAndrew 2016 - Forum software by © MyBB