skip to Main Content

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', 'ApiTest::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?

2

Answers


  1. I’m going through this case too

    Login or Signup to reply.
  2. According to the CodeIgniter Docs:

    Options passed to the outer group() (for example namespace and filter) are not merged with the inner group() 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', 'ApiTest::index');
    });
    

    The filters are getting called in the order they are assigned.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search