Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding Filters / Filter arguments no longer working in v4.6.0 #9422

Closed
NSURLSession0 opened this issue Jan 19, 2025 · 1 comment
Closed

Comments

@NSURLSession0
Copy link
Contributor

NSURLSession0 commented Jan 19, 2025

PHP Version

8.1

CodeIgniter4 Version

4.6.0

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

macOS, Linux

Which server did you use?

fpm-fcgi

Database

No response

What happened?

After change #8977 overriding filter arguments is no longer working.

Before I could do:

// Config/Routes.php
$routes->group('authentication', ['filter' => 'portal:public'], function ($routes) { // Pass argument 'public' to portal filter
    $routes->addRedirect('/', 'authentication/login');
});


// Config/Filters.php
public array $globals = [
    'before' => ['portal'], // Before 4.6.0, this filter would get overridden by the filter in Routes.php
    'after'  => [
    'secureheaders' => [],
        'toolbar' => [],
    ],
];

After the change in 4.6.0, the filter is called twice: once without the argument and once with the argument 'public'. If this is intentional, what should I do to get the old behavior back? I am using the old filter order ($oldFilterOrder = true), in case that matters.

Steps to Reproduce

Use the same filter in Routes.php and within globals in Filters.php, but use different arguments in both cases.

Expected Output

Arguments from globals are used when $oldFilterOrder is set to false. The value from routes is used when $oldFilterOrder is true. However, since version 4.6.0, the filters are executed twice, each with their own arguments.

Anything else?

No response

@NSURLSession0 NSURLSession0 added the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 19, 2025
@NSURLSession0 NSURLSession0 changed the title Bug: Overriding Filters no longer working in v4.6.0 Bug: Overriding Filters / Filter arguments no longer working in v4.6.0 Jan 19, 2025
@michalsn
Copy link
Member

Changes in filters are marked as a breaking change.

To prevent calling the "portal" filter twice, simply use except:

public array $globals = [
    'before' => [
        'portal' => ['except' => ['authentication*']],
    ],
    // ...
];   

@michalsn michalsn removed the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 19, 2025
@paulbalandan paulbalandan changed the title Bug: Overriding Filters / Filter arguments no longer working in v4.6.0 Overriding Filters / Filter arguments no longer working in v4.6.0 Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants