CodeIgniter Forums
Apply multiple filters to a single route - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Apply multiple filters to a single route (/showthread.php?tid=77176)



Apply multiple filters to a single route - mlurie - 07-28-2020

I am just getting back into PHP programing after a few years and started with CodeIgniter 4. It is the first framework I have used and I love it.  There is one feature that does seem to be missing though.  The ability to apply multiple filters to a single route would be amazing.  I understand that I can create a filter alias that includes multiple filter classes, but this is kind of falls apart if you need to pass different arguments to those individual filters in a single alias.  Also, creating multiple aliases for each filter combination can get tedious.


RE: Apply multiple filters to a single route - korgoth - 07-31-2020

+1 to that. Another useful thing would be to be able to pass parameters from the URL to filters.

That way if we have an ID defined in some segment of the URL could pass it to a filter and use it there.

I am currently doing this getting the segment form the URL in the filter itself but thats not very good.


RE: Apply multiple filters to a single route - MGatner - 08-06-2020

You can definitely have multiple filters for a route. I use this regularly from Filters.php. I guess the issue is defining them in Routes.php? Something on my “to do” list is to make filters defined in Filters.php accept arguments, which might be a better way to solve this.


RE: Apply multiple filters to a single route - korgoth - 08-08-2020

(08-06-2020, 04:41 AM)MGatner Wrote: You can definitely have multiple filters for a route. I use this regularly from Filters.php. I guess the issue is defining them in Routes.php? Something on my “to do” list is to make filters defined in Filters.php accept arguments, which might be a better way to solve this.

Yes, what we mean is being able to define multiple filters (each of them with arguments - and some of those arguments from the route itself) in Routes.php. When you want to have different combinations for different routes its very very inconvenient having to define each combination in filters.php


RE: Apply multiple filters to a single route - kenjis - 01-22-2023

See https://codeigniter4.github.io/CodeIgniter4/incoming/routing.html#multiple-filters