Welcome Guest, Not a member yet? Register   Sign In
Multiple filters set on a route in routes.php
#1

How would I define different multiple before and after filters for a route in the routes.php config file.
When I define the filters
PHP Code:
$routes->get'beelevels''Beelevels::index', [
   'filter' => [
      'authorize',
      'permissions:view,lookups',
   ]
] ); 
the filter are attached to both before and after, if I define the filters
PHP Code:
$routes->get'beelevels''Beelevels::index', [
   'filter' => [
      'before' => [
         'authorize',
         'permissions:view,lookups',
      ]
   ]
] ); 
I get an exception
Code:
CodeIgniter\Filters\Filters::enableFilter(): Argument #1 ($name) must be of type string, array given, called in ....\system\Filters\Filters.php on line 547
at SYSTEMPATH\Filters\Filters.php:486

The documentation on multiple routes is a bit light.
Dirk B.
Abatrans Software
No SEO spam - see forum guidelines
Reply
#2

You cannot. There is no such feature.
Reply
#3

You can achieve this by using a condition ( if) or (switch) in a single filter class and property but not by that
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#4

(04-29-2024, 05:43 PM)kenjis Wrote: You cannot. There is no such feature.

Perhaps add it to the wish list for the next release.

In my case I would like the filters to only be added to the before and not to the after as well. If I needed to add filters to the AFTER event my App/Config/Filters.php file becomes a nightmare to maintain.
Dirk B.
Abatrans Software
No SEO spam - see forum guidelines
Reply
#5

Why don't you write filters that work only in before?
Reply
#6

(04-30-2024, 02:20 AM)kenjis Wrote: Why don't you write filters that work only in before?

I have 145 routes and counting and it just seem easier to add the filters to the route definitions rather than adding the routes to config/filters.php.  It looks like I will have to re-evaluate what the best method for my application will be. Perhaps go to a method based i.s.o. route based.
Dirk B.
Abatrans Software
No SEO spam - see forum guidelines
Reply
#7

I meant, why don't you create your own filters that work only in before?
That is, no code in the after() method.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB