Welcome Guest, Not a member yet? Register   Sign In
Filters only for to use in route entries
#1

(This post was last modified: 03-11-2020, 11:55 PM by aybarsm.)

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']);
});
Reply
#2

(This post was last modified: 06-13-2020, 01:44 AM by jreklund.)

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']);
}
); 
Hernan Rodríguez
[email protected]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB