CodeIgniter Forums

Full Version: Get controller name and method
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How am I able to get the controller name and method in a filter?
I' am not sure if these will work in a filter or not.

get_class ($object); // Returns the name of the class of an object
get_called_class (); // The "Late Static Binding" class name
get_parent_class ($object); // Retrieves the parent class name for object or class
gettype ($var); // Get the type of a variable

is_subclass_of ($object, $class_name, $allow_string = TRUE); // Checks if the object has this class as one of its parents or implements it

get_class_methods ($class_name); // Gets the class methods' names
get_class_vars ($class_name); // Get the default properties of the class
get_object_vars ($object); // Gets the properties of the given object
The routing has already been done at that point since it knows what controller to run, so you can always grab the Router instance and get them from there:

$router = service('router');
$controller  = $router->controllerName();
$method = $router->methodName();
Aww, so we do have something like CI 3 had thanks Lonnie.