CodeIgniter Forums
Best way to get which route was called (for Filter classes) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Best way to get which route was called (for Filter classes) (/thread-74862.html)



Best way to get which route was called (for Filter classes) - AcidSlide - 11-16-2019

Hi there,

Can somebody suggest what is the best way to know which route was called from a controller or filter class?

Please don't say use uri_string() as this won't work for projects that uses baseURLs with a subpath.  I want to check (from my before() function in my custom filter) which route (or controller) was being called by the request.

Thanks in advance  Big Grin Big Grin


RE: Best way to get which route was called (for Filter classes) - MGatner - 11-17-2019

I used to do something like that in my assets module. See if this helps:
https://github.com/tattersoftware/codeigniter4-assets/blob/131f1b8c04d894f1b0e351d7c2523b744c184db5/src/Assets.php#L121