CodeIgniter Forums
variables - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: variables (/showthread.php?tid=14609)



variables - El Forum - 01-08-2009

[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?


variables - El Forum - 01-08-2009

[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).


variables - El Forum - 01-09-2009

[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?