Search code examples
phpcodeignitercodeigniter-2codeigniter-routing

get the requested controller in hook precontroller in codeigniter


I'm trying to make a simple routing rule to allow only authenticated users to certain controllers.

To achieve this, I would like to run precontroller hook and check if the user is logged in using ci session. However, I have to know which controller the user wants to access. How do I know this in a hook function?


Solution

  • $this->router->fetch_class();

    Extend CI_Controller and this should work.