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

[eluser]Russell Keith[/eluser]
I might just be dense, but where can I declare a variable for use throughout the application? I want to declare a variable to hold the username and be able to call it from any function in my controller. Is this possible?
#2

[eluser]Colin Williams[/eluser]
A lot of options. It could be a property of one of your library classes. It could be a config item. It could be a property of the $CI superobject. Take your pick, but I recommend using a property of the class that represents or manages the user object: so, a model or library. The user library I use has a current() method that returns the current user object (logged in user).
#3

[eluser]darkhouse[/eluser]
What a session variable? I like Colin's idea of a user library that gets a user object, which obviously would contain the username, and that probably is the BEST solution, but probably the most work also. And it would likely work with a session anyways, like storing the user id in a session, and getting the data based on that... so if all you need is the username, why not just store that in the session also?




Theme © iAndrew 2016 - Forum software by © MyBB