Search code examples
codeignitercodeigniter-4

Codeigniter 4 Current/Active Controller


In Codeigniter 3 is possible to get current active class and method with this code:

    $active_controller = $this->router->fetch_class();
    $active_function = $this->router->fetch_method();

Are there such functions in Codeigniter 4?


Solution

  • In CodeIgniter 4

    $router = service('router'); 
    $controller  = $router->controllerName();  
    
    $router = service('router');
    $method = $router->methodName();