How can I can set a global variable for the username of the logged-in user? At the moment i have the following code in all my controllers to get the username. I rather set it as a global variable if possible.


I tried putting the same code in the file but it gave me the following error message: "No object (name: request) has been registered for this thread"

Was it helpful?


There is no single "logged-in user" if you're serving requests on multiple threads -- by setting a single global variable the threads would trample upon each other and end up very very confused on who "the logged-in user" actually is. There is (at most;-) a single logged-in user per request, so keeping that info in the request object seems vastly preferable;-).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow