• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.