CI4 How to get controller name only - 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: CI4 How to get controller name only (/showthread.php?tid=81311) |
CI4 How to get controller name only - serialkiller - 02-15-2022 Using PHP Code: service('router')->controllerName(); Returns for example \App\Controllers\Mycontroller Is there something like fetch_class() in CI3 that just returns the controller name? I just need "mycontroller" Or do I have to split the string to get it? RE: CI4 How to get controller name only - paulbalandan - 02-15-2022 class_basename echo class_basename(service('router')->controllerName()); // Mycontroller RE: CI4 How to get controller name only - serialkiller - 02-15-2022 (02-15-2022, 05:48 AM)paulbalandan Wrote: class_basename Perfect thank you very much |