Welcome Guest, Not a member yet? Register   Sign In
Applying multiple filters on a single route definition
#1

I have tried ti find a solution but failed so far - is it possible to apply multiple filters on a single route? 

I have tried the following with no luck

PHP Code:
$routes->get('/''Dashboard::index', ['filter' => 'auth|second_filter']);
$routes->get('/''Dashboard::index', ['filter' => ['auth''second_filter']]); 

It seems that the parameter only accepts strings and not arrays and having to define each set of possible filters as an alias is not very convenient
Reply
#2

Bump! I would also like to know the answer to this question.
Reply
#3

(This post was last modified: 07-27-2020, 07:32 PM by mlurie.)

I found the answer in the documentation. Multiple filters can be assigned to a single alias: https://www.codeigniter.com/user_guide/i...l?#aliases. Then that alias can be applied to a route which accomplishes the same thing as applying multiple filters to a single route. I would suggest that this be added to the URI Routing section of the manual in addition to the Filters section where the documentation is currently located.
Reply
#4

(07-27-2020, 07:31 PM)mlurie Wrote: I found the answer in the documentation. Multiple filters can be assigned to a single alias: https://www.codeigniter.com/user_guide/i...l?#aliases.  Then that alias can be applied to a route which accomplishes the same thing as applying multiple filters to a single route.  I would suggest that this be added to the URI Routing section of the manual in addition to the Filters section where the documentation is currently located.

While that is true and working - its not the best solution when you want to pass some parameters to the filters. Also if you have more than a couple of filters you should write a different alias for each combination which is not convenient
Reply
#5

(07-27-2020, 11:35 PM)korgoth Wrote:
(07-27-2020, 07:31 PM)mlurie Wrote: I found the answer in the documentation. Multiple filters can be assigned to a single alias: https://www.codeigniter.com/user_guide/i...l?#aliases.  Then that alias can be applied to a route which accomplishes the same thing as applying multiple filters to a single route.  I would suggest that this be added to the URI Routing section of the manual in addition to the Filters section where the documentation is currently located.

While that is true and working - its not the best solution when you want to pass some parameters to the filters. Also if you have more than a couple of filters you should write a different alias for each combination which is not convenient
 
I agree this is not the best solution.  I would much rather be able to apply multiple filters to a single route.  I'm going to put in a feature request here: https://forum.codeigniter.com/forum-29.html.  Maybe if you do the same, it will get noticed.
Reply
#6

(This post was last modified: 01-08-2022, 10:40 AM by arma7x.)

Bump! I would also like to know the answer to this question.

Edit:
Filter arguments(https://www.codeigniter.com/user_guide/i...-arguments)
- My problem is not all filter receive same $arguments

Solution:
- https://github.com/arma7x/Parry/blob/mas...hp#L39-L46
- https://github.com/arma7x/Parry/blob/mas...ilters.php
- only support ['filter' => 'checkMinLevel:0|hasReadPerm']
Keep calm.
Reply
#7

Since v4.1.5, multiple filters can be set.
See https://codeigniter4.github.io/userguide...ng-filters
Reply
#8

try using route group
https://codeigniter.com/user_guide/incom...ing-routes
Reply




Theme © iAndrew 2016 - Forum software by © MyBB