Skip to content

Filter on route group only attach / #1247

Closed
@uno-de-piera

Description

@uno-de-piera

Hi CodeIgniter team:

The filter api-auth only works with GET request on base path:

// Routes.php
$routes->group(
    'api',
    ['namespace' => 'App\Controllers\Api', 'filter' => 'api-auth'],
    function(\CodeIgniter\Router\RouteCollection $routes) {
        $routes->resource('posts', [
            'controller' =>'PostController',
        ]);
    }
);

| api/posts | get | \App\Controllers\Api\PostController::index works
| api/posts/new | get | \App\Controllers\Api\PostController::new doesn't work
| api/posts/(.)/edit | get | \App\Controllers\Api\PostController::edit/$1 doesn't work
| api/posts/(.
) | get | \App\Controllers\Api\PostController::show/$1 doesn't work
| api/posts | post | \App\Controllers\Api\PostController::create doesn't work
| api/posts/(.) | put | \App\Controllers\Api\PostController::update/$1 doesn't work
| api/posts/(.
) | delete | \App\Controllers\Api\PostController::delete/$1 doesn't work

I'm reviewing and I see that it works in the following way:

// Routes.php
$routes->group(
    'api',
    ['namespace' => 'App\Controllers\Api'],
    function(\CodeIgniter\Router\RouteCollection $routes) {
        $routes->get('courses/(:num)', 'CourseController::show/$1');
        $routes->resource('courses', [
            'controller' =>'CourseController',
        ]);
    }
);

// Filters.php
public $filters = [
    'api-auth' => ['before' => ['api*']]
];

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix themwaiting for infoIssues or pull requests that need further clarification from the author

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions