Welcome Guest, Not a member yet? Register   Sign In
Confused about variables
#10

(This post was last modified: 07-29-2016, 09:55 AM by mwhitney.)

(07-29-2016, 08:44 AM)MightBeABitLate Wrote: Gentleman,

Those responses are absolutely brilliant and have provided answers to the questions that I have been asking for days. Thank you very much indeed for taking the time to post.

I see now that I hadn't quite grasped the concept of statelessness that comes with dealing with web pages.

One final question to just clear things up well and truly. Does all this mean that what are often called variables when referring to controllers are actually just statics, and are more akin to constants given that the controller and everything associated with it are destroyed once the view is rendered and served out to the user?

Thanks again for two very very useful posts.

JB

The previous answers probably do a good enough job of describing the differences between static variables, constants, and just plain variables. CI's Controller can add to the confusion because it incorporates the use of static variables to load many of its classes as Singletons (including the Controller itself), and most of your code will run within that Singleton.

So, a property on a Controller is a property of a class which happens to be executed as a static variable, but the property itself is not static (unless it was defined as static). Since most of your code is executed within the scope of the Controller, with access to most of the Controller's properties and methods, it's possible that your property can be accessed by most of the other code executed after it is defined. However, if you define properties in your Controller specifically for the purpose of accessing them from other classes, you will find that it limits your ability to reuse your code. It also can make it very difficult to read and understand the code later.
Reply


Messages In This Thread
Confused about variables - by MightBeABitLate - 07-27-2016, 03:35 PM
RE: Confused about variables - by InsiteFX - 07-28-2016, 04:28 AM
RE: Confused about variables - by mwhitney - 07-28-2016, 10:24 AM
RE: Confused about variables - by MightBeABitLate - 07-29-2016, 05:06 AM
RE: Confused about variables - by mwhitney - 07-29-2016, 07:26 AM
RE: Confused about variables - by dave friend - 07-29-2016, 08:27 AM
RE: Confused about variables - by MightBeABitLate - 07-29-2016, 08:44 AM
RE: Confused about variables - by mwhitney - 07-29-2016, 09:53 AM
RE: Confused about variables - by dave friend - 07-29-2016, 09:05 AM
RE: Confused about variables - by PaulD - 07-29-2016, 09:11 AM
RE: Confused about variables - by MightBeABitLate - 07-29-2016, 10:42 AM
RE: Confused about variables - by dave friend - 07-29-2016, 11:28 AM
RE: Confused about variables - by MightBeABitLate - 07-29-2016, 11:54 AM
RE: Confused about variables - by mwhitney - 07-29-2016, 12:17 PM
RE: Confused about variables - by fmertins - 07-29-2016, 01:14 PM
RE: Confused about variables - by mwhitney - 07-29-2016, 02:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB