Welcome Guest, Not a member yet? Register   Sign In
Get controller name and method
#1

How am I able to get the controller name and method in a filter?
Reply
#2

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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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:

Code:
$router = service('router');
$controller  = $router->controllerName();
$method = $router->methodName();
Reply
#4

Aww, so we do have something like CI 3 had thanks Lonnie.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(06-03-2019, 06:34 AM)kilishan Wrote: 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:

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


Hi,

This was exactly what i was looking for, but i want to ask a few things.

By doing $router = service('router'); am i grabbing the already initiated service or creating a new one. 

Also is this a part of the docs, i mean did i miss something, or its something i should have already been aware of.
Reply
#6

Thanks guys, Interesting!
I searched the userguide for more info on this router service (and its methods), but I come home empty handed... Suggestions on where to find more?

Cheers,

Zeff
Reply




Theme © iAndrew 2016 - Forum software by © MyBB