Welcome Guest, Not a member yet? Register   Sign In
Unexpected variable behaviour in nested views
#1

[eluser]zagrad[/eluser]
I think this is not an actual bug, so I decided to not post it in the Bug Report section, but in the discussion forum instead.

As you might know the view loader caches variables. The comments at line 639 of Loader.php state the following:

Quote:/*
* Extract and cache variables
*
* You can either set variables using the dedicated $this->load_vars()
* function or via the second parameter of this function. We'll merge
* the two types and cache them so that views that are embedded within
* other views can have access to these variables.
*/

In my situation this is causing unexpected behaviour, and I am very curious if anyone else has had this problem and what's the best solution.

First my problem:
I am working with nested views. Let's say my nesting is as follows:

- View 'master.php' is the root template
- View master.php calls view 'sub.php' multiple times

When master.php calls sub.php the first time, it also sends some variables to that view:

Code:
$this->load->view('sub',Array('var1' => 123, 'var2' => 456));

When master.php calls sub.php the second time, it sends other or less variables.

Code:
$this->load->view('sub',Array('var1' => 789));

Now the problem occurs: the sub-view still has var2 filled, even though I don't want it to be. Ofcourse I could empty var2, each time I call the sub-view, but I think that should not be the way.

I believe that when sending variables to a view, it should be available to that particulair instance of that particulair view and all of it's child views.

Please tell me why you agree or disagree and/or if I'm making a mistake in my logic.
Should we fix this?

Gr,
Paul

BTW: I am mostly familiar with working with Smarty. In Smarty the above rules do apply.




Theme © iAndrew 2016 - Forum software by © MyBB