CodeIgniter Forums
Avoid using CI4 filters - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Best Practices (https://forum.codeigniter.com/forum-12.html)
+--- Thread: Avoid using CI4 filters (/thread-78708.html)



Avoid using CI4 filters - MrWhite - 02-28-2021

I think this is one of the very poorly implimented features in CI4.

01. It's doesn't support for multiple filters for single route.

02. There is no support for chained filters like in the form validation. For this reason we have to do authentication like stuff in every filters and its get repeated in every filter.

03. There is no better way to know which route we are currently on in the filters. We have to do lots of if() block just to verify routes.

So I suggest you to use old school type methods. like,

Do stuff top of the controller method or end of the controller method. I know it's looks bad but it's much more simpler and well scale.

Thanks.


RE: Avoid using CI4 filters - kenjis - 02-28-2021

You can combine multiple filters into one alias, making complex sets of filters simple to apply:

PHP Code:
public $aliases = [
    'apiPrep' => [
        \App\Filters\Negotiate::class,
        \App\Filters\ApiAuth::class,
    ]
]; 
https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html#aliases


RE: Avoid using CI4 filters - MrWhite - 02-28-2021

(02-28-2021, 07:38 PM)kenjis Wrote: You can combine multiple filters into one alias, making complex sets of filters simple to apply:

PHP Code:
public $aliases = [
    'apiPrep' => [
        \App\Filters\Negotiate::class,
        \App\Filters\ApiAuth::class,
    ]
]; 
https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html#aliases

But passing filter specific params for multiple filters is still a nightmare.


RE: Avoid using CI4 filters - kenjis - 02-28-2021

Oh, I see.