To get current Controller and Function/Action in CodeIgniter, we can call $this->uri->segment(n) of URI Class which is initialized automatically.
For example:
<?php function check_permission() { /* ... */ $controller = $this->uri->segment(1); $action = $this->uri->segment(2); /* ... */ } ?> |
Or if we want to retrieve the current controller and function/action in a helper function, we can do this:
<?php function check_permission() { /* ... */ $ci = get_instance(); $controller = $ci->uri->segment(1); $action = $ci->uri->segment(2); /* ... */ } ?> |