Welcome Guest, Not a member yet? Register   Sign In
Accessing controller public variables from multiple methods
#6

[eluser]chuckl[/eluser]
After looking at this a bit longer it appears as though each function call is getting a fresh instantiation of the controller which means a new data variable.

After more testing I am convinced that while this may be “Works As Coded” it is not the correct implementation. In system/core/CodeIgniter.php around line 267 it appears that CI instantiates a new controller object every time any controller method is called. Controllers should be instantiated as singleton objects which would allow for class variable access.

As it currently is coded class level variables will never work because you get a new instance of the class every time you call a method of the class. I guess I will have to store all of my class data values on the session stack in the meantime. Not a good thing though.


Messages In This Thread
Accessing controller public variables from multiple methods - by El Forum - 04-01-2011, 02:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB