Reputation: 23
I'm having hard time to configure nested groups in CI 4. I'm trying to configure the access to routes passing thru a group of filters to authenticate and validate the data that i'm using in the controller.
Here's a example of the configuration:
$routes->group('api/', ['filter' => 'jwt'], function ($routes) {
$routes->group('', ['filter' => 'scopefilter:test'], function ($routes) {
$routes->post('test', 'Api\Test::index');
});
});
In this case, the only filter that worked is the scopefilter. The jwt is invisible. The expecting behavior was that the request should pass thru jwt filter and than the scopefilter.
Has anyone already solved this?
Upvotes: 2
Views: 593
Reputation: 466
According to the CodeIgniter Docs:
Options passed to the outer
group()
(for examplenamespace
andfilter
) are not merged with the innergroup()
options.
As your inner group has no actual route definition, why not insert the filter in the outer group like so:
$routes->group('api/', ['filter' => ['jwt', 'scopefilter:test']], function ($routes) {
$routes->post('test', 'Api\Test::index');
});
The filters are getting called in the order they are assigned.
Update due to IF Ferreiras comment:
For this to work you have to enable multiple filters in Config/Feature.php
:
public bool $multipleFilters = true;
Upvotes: 1