Welcome Guest, Not a member yet? Register   Sign In
Filter run order
#1

I have a filter being ran off of a route. Is there a way to make sure other filters run before the filter on the route?

PHP Code:
     public $aliases = [
        
'csrf'         => \CodeIgniter\Filters\CSRF::class,
        
'toolbar'      => \CodeIgniter\Filters\DebugToolbar::class,
        
'honeypot'     => \CodeIgniter\Filters\Honeypot::class,
        
'options'      => \App\Filters\Options::class,
        
'authenticate' => \App\Filters\AuthFilter::class,
        
'permission'   => \App\Filters\PermissionFilter::class,
    ];

   $routes->get('admin''Admin::index', ['filter' => 'permission:admin']); 

The problem I'm having is that options and authenticate filters are running after the permission filter. Is there a way to make sure my options and authenticate filters run first?

Thanks in advance.
Reply
#2

(09-02-2020, 06:17 PM)ogomez Wrote: I have a filter being ran off of a route. Is there a way to make sure other filters run before the filter on the route?

PHP Code:
     public $aliases = [
        
'csrf'         => \CodeIgniter\Filters\CSRF::class,
        
'toolbar'      => \CodeIgniter\Filters\DebugToolbar::class,
        
'honeypot'     => \CodeIgniter\Filters\Honeypot::class,
        
'options'      => \App\Filters\Options::class,
        
'authenticate' => \App\Filters\AuthFilter::class,
        
'permission'   => \App\Filters\PermissionFilter::class,
    ];

   $routes->get('admin''Admin::index', ['filter' => 'permission:admin']); 

The problem I'm having is that options and authenticate filters are running after the permission filter. Is there a way to make sure my options and authenticate filters run first?

Thanks in advance.

Only one filter runs per route, so redesign the permission filter to run any code that it depends on first.
Reply
#3

(This post was last modified: 09-06-2020, 02:22 AM by Gary.)

I take it that your permission filter runs on every call... surely if you simply remove the filter option and use: $routes->get('admin', 'Admin::index'); it would work in the desired manner?

If it's not, then you could stop the permissions filter from where it's not wanted using:
'permission' => ['except' => ['Index/*',... in your Filter's $globals variable.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB