I want to create a global object that represents the current user in Code Igniter. The constructor of the object takes the user id, which is stored in $_SESSION['user_id'].
Every time a user visits a page, I want to create this user object. Where should I instantiate it? I think instantiating it in config/constants.php works, but is there a more standard/reliable place to instantiate it?
One option is to create a
MY_Controllerfrom which all your other controllers would inherit. The user object could be instantiated withinMY_Controllerand therefore would be available in every controller which inherits from it.Simplified example: