CodeIgniter Forums
Filters only for to use in route entries - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Filters only for to use in route entries (/showthread.php?tid=75741)



Filters only for to use in route entries - aybarsm - 03-11-2020

Hello all,

I am first time user of CodeIgniter started directly with 4.0.2. Have to say, congrats to everyone who was involved and of course thank you all.

So my question:
I would like to declare a filter in order to use with just in Routes.php like below. Even though I have declared my filter alias in Filters.php, it seems that filter does not load without declaring it in $filters.

I don't want to declare it in $filters because I have clashing routes and {locale}/ master route which is causing a lot of trouble to me already and also causing a lot trouble with regex-like $filters

Is there any way to achieve to do this? Should I try something from an unusual way? I am 'follow the rules' guy, so I thought maybe I am missing something and wanted to ask.

Filters.php entry:
Code:
public $aliases = [
    'auth-client' => \App\Filters\AuthClient::class,
    'csrf'     => \CodeIgniter\Filters\CSRF::class,
    'toolbar'  => \CodeIgniter\Filters\DebugToolbar::class,
    'honeypot' => \CodeIgniter\Filters\Honeypot::class,
];

public $filters = [];



Routes.php entry:

Code:
$routes->group('client', ['filter'=>'auth-client'], function($routes) {
    $routes->get('/', 'Client::dashboard', ['as'=>'dashboardClient']);
});



RE: Filters only for to use in route entries - Hrodriguez18 - 06-12-2020

In fact I also have this problem, I am following the rules, declared the alias and I want to use the filter only on the path.


PHP Code:
public $aliases = [
'csrf'    => \CodeIgniter\Filters\CSRF::class,
'toolbar'  => \CodeIgniter\Filters\DebugToolbar::class,
'honeypot' => \CodeIgniter\Filters\Honeypot::class,
'admin-auth' => \App\Filters\FilterApiAuth::class
]; 

PHP Code:
$routes->group('api', ['namespace' => 'App\Api'], function($routes)
{
    $routes->resource('Auth');
    $routes->resource('Ftp',['filter' => 'admin-auth']);
}
);