Welcome Guest, Not a member yet? Register   Sign In
global objects
#1

[eluser]Dennis_gull[/eluser]
Is there a best practice for global objects in CI? I currently keep protected variables in MY_controller but I won't be able to access them in my model.

I know two ways to solve this, I can either use "global $user" or put the user in a singleton however I think using a singleton is a little overkill so if there is no other way to pass data to each model automatically I think I will go with the global alternative.

By the way, can't I extend model and pass over the user from the controller in some way?
#2

[eluser]jgetner[/eluser]
there is many ways to grab your class properties without having to use globals best suggestion and overall best practice of php is to just build a simple method to call that classes properties.

i would suggest it being static so you can use that method globally if you remember to keep the class in scope.
#3

[eluser]Dennis_gull[/eluser]
I totally forgot about static variables, thanks for the help.




Theme © iAndrew 2016 - Forum software by © MyBB