The idea is to catch any access to controller’s functions and, if we are authenticated, rout as normal and, if not, show the login form.
The question is, is _remap function the best place to check for access to controller’s functions and how to pass routing back to CI in case we are authenticated?
_remapisn’t necessary for this. You could use it, but you don’t need to.Check for access in the
__construct()method of the controller. You can get the current method via$this->router->fetch_method()and authenticate against that.Better yet, have all your controller that need this extend a base controller (aka “MY_Controller”). You can write an
Auth_Controllerand do the auth check in the__construct()there. You can get the current class via$this->router->fetch_class(), as well as the method, just make sure your controllers that need this extendAuth_Controllerinstead of the usualCI_Controller.If they shouldn’t have access, just redirect them where they need to go or show an error.