How to Get Current Controller and Method Name in CodeIgniter

If you want to implement conditional code based on the class or method, you need to get current class and method name in CodeIgniter. Using the Router Class in CodeIgniter, you can easily get the current controller and method name. The Router class helps to parses URIs and determines routing. The fetch_class() and fetch_method() method of Router class can be used to read the class and method property in CodeIgniter.

Fetch Current Class Name
Use fetch_class() method to get the name of the controller or class in CodeIgniter.

$this->router->fetch_class()

Fetch Current Method Name
Use fetch_method() method to get the name of the method or function in CodeIgniter.

$this->router->fetch_method()

Leave a reply

keyboard_double_arrow_up