CodeIgniter v4.0.2: Current class and method names - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: CodeIgniter v4.0.2: Current class and method names (/showthread.php?tid=75761) |
CodeIgniter v4.0.2: Current class and method names - Bennito254 - 03-13-2020 How can I fetch the names of the currently displayed controller class and the method? RE: CodeIgniter v4.0.2: Current class and method names - John_Betong - 03-13-2020 Try this: https://www.php.net/manual/en/language.constants.predefined.php RE: CodeIgniter v4.0.2: Current class and method names - Bennito254 - 03-13-2020 What about from a helper, or a library. RE: CodeIgniter v4.0.2: Current class and method names - Bennito254 - 03-13-2020 Found a solution: Can be used in helpers too. PHP Code: $router = \Config\Services::router(); RE: CodeIgniter v4.0.2: Current class and method names - MGatner - 03-13-2020 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() RE: CodeIgniter v4.0.2: Current class and method names - Bennito254 - 03-13-2020 (03-13-2020, 10:54 AM)MGatner Wrote: You want the Router class, and the following methods: contrrollerName(), methodName() Yeah, I got that. Admin has not yet approved my comment. |