• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Views and passed variable scopes

#1
There is a CI3-related topic raised [email protected] that is interesting for CI4 development, I think. Briefly, the expectation is that passed variables within a view should be isolated within its scope only. "Global" variables might be passed explicitly.

Here is the link: http://forum.codeigniter.com/thread-6496...31236.html
Reply

#2
Good call. It was holding on to the data, but I just pushed a change that will reset the data after each render() call by default, with the option to keep it.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#3
(04-15-2016, 08:05 AM)kilishan Wrote: Good call. It was holding on to the data, but I just pushed a change that will reset the data after each render() call by default, with the option to keep it.

IMO, that data shouldn't be cached at all, and therefore you shouldn't have the option to keep it - just render the view and immediately discard any variables.
Reply

#4
(04-15-2016, 08:50 AM)Narf Wrote: IMO, that data shouldn't be cached at all, and therefore you shouldn't have the option to keep it - just render the view and immediately discard any variables.

Personally, I've found it handy in the past to have any views loaded within another view (like a main layout) to have access to variables set by other views. Other times, it's annoying. Smile But I think there are definitely use cases both ways. It defaults to trashing the data so most people will use it that way, I'm sure, but the option is available if they decide they need it.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#5
(04-15-2016, 09:05 AM)kilishan Wrote:
(04-15-2016, 08:50 AM)Narf Wrote: IMO, that data shouldn't be cached at all, and therefore you shouldn't have the option to keep it - just render the view and immediately discard any variables.

Personally, I've found it handy in the past to have any views loaded within another view (like a main layout) to have access to variables set by other views. Other times, it's annoying. Smile But I think there are definitely use cases both ways. It defaults to trashing the data so most people will use it that way, I'm sure, but the option is available if they decide they need it.

I did too think of the view-within-a-view scenario, but it's the same thing - you can pass those variables to it on the spot.

The current behavior can be handy, of course (otherwise it wouldn't exist), but if it does remain as an optional feature then it has to really be optional all the way. If I don't turn it on, I wouldn't expect any variables to be cached behind the scenes just so they can be later reset by default.
Reply

#6
(04-15-2016, 10:19 AM)Narf Wrote: I did too think of the view-within-a-view scenario, but it's the same thing - you can pass those variables to it on the spot.

The current behavior can be handy, of course (otherwise it wouldn't exist), but if it does remain as an optional feature then it has to really be optional all the way. If I don't turn it on, I wouldn't expect any variables to be cached behind the scenes just so they can be later reset by default.

Yup, that's how it's implemented. after the data is extracted to the view, the class' data property is reset to an empty array by default.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#7
(04-15-2016, 10:28 AM)kilishan Wrote:
(04-15-2016, 10:19 AM)Narf Wrote: I did too think of the view-within-a-view scenario, but it's the same thing - you can pass those variables to it on the spot.

The current behavior can be handy, of course (otherwise it wouldn't exist), but if it does remain as an optional feature then it has to really be optional all the way. If I don't turn it on, I wouldn't expect any variables to be cached behind the scenes just so they can be later reset by default.

Yup, that's how it's implemented. after the data is extracted to the view, the class' data property is reset to an empty array by default.

I guess you've misread my post - I'm saying it should NOT be implemented that way.
There's no point in populating a class property if you're going to reset its value in the very same method call.
Reply

#8
(04-15-2016, 10:36 AM)Narf Wrote:
(04-15-2016, 10:28 AM)kilishan Wrote:
(04-15-2016, 10:19 AM)Narf Wrote: I did too think of the view-within-a-view scenario, but it's the same thing - you can pass those variables to it on the spot.

The current behavior can be handy, of course (otherwise it wouldn't exist), but if it does remain as an optional feature then it has to really be optional all the way. If I don't turn it on, I wouldn't expect any variables to be cached behind the scenes just so they can be later reset by default.

Yup, that's how it's implemented. after the data is extracted to the view, the class' data property is reset to an empty array by default.

I guess you've misread my post - I'm saying it should NOT be implemented that way.
There's no point in populating a class property if you're going to reset its value in the very same method call.

Then you haven't looked at the class in question. There are additional methods to allow you to set data, so it needs to be collected in a class variable. Otherwise, you're correct, if it was all handled in the same method it would be pointless.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#9
(04-15-2016, 10:42 AM)kilishan Wrote: Then you haven't looked at the class in question. There are additional methods to allow you to set data, so it needs to be collected in a class variable. Otherwise, you're correct, if it was all handled in the same method it would be pointless.

I haven't, indeed. I'm just replying to what you've said in this thread. Smile

I stand by what I've said though - cache shouldn't be cleared by default, but not stored in the first place (unless explicitly requested).
Reply

#10
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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.