Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter v4.0.2: Current class and method names
#1

How can I fetch the names of the currently displayed controller class and the method?
Reply
Reply
#3

What about from a helper, or a library.
Reply
#4

Found a solution:
Can be used in helpers too.
PHP Code:
    $router = \Config\Services::router();
    $_method $router->methodName();
    $_controller $router->controllerName(); 
Reply
#5

You want the Router class, and the following methods: contrrollerName(), methodName()
You can get it directly from the service as well:

$controller = services(‘router’)->controllerName()
Reply
#6

(This post was last modified: 03-13-2020, 11:02 AM by Bennito254.)

(03-13-2020, 10:54 AM)MGatner Wrote: You want the Router class, and the following methods: contrrollerName(), methodName()
You can get it directly from the service as well:

$controller = services(‘router’)->controllerName()

Yeah, I got that. Admin has not yet approved my comment.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB