• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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

#2
Try this:

https://www.php.net/manual/en/language.c...efined.php
download and make your system directory strict
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
(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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.