-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Bug: nested $routes->group() with same filter name doesn't work as exepcted #8973
Comments
I have confirmed this behavior. @codeigniter4/core-team https://codeigniter4.github.io/CodeIgniter4/incoming/routing.html#nesting-groups |
@kenjis For the time being, I'll work around this by creating multiple filters with different names. Your remark about the docs and Nesting Groups; I think the example and its description is misleading. The code works only if the names are different, not like in the example code. |
It seems we need to discuss the expected use cases and the expected behavior. Is there a possible use case where the same filter is executed more than once?
Yes, the current user guide explanation is wrong due to this issue. |
Maybe my implementation is flawed but I have a
Users have different access to different places in the system. In my routes I have multiple filter options such as In my process of tidying up $routes->group(
'config',
['except' => ['new', 'edit'], 'filter' => 'bearer-auth:conf'],
static function ($routes) {
// ....
$routes->group('tangix', ['filter' => 'auth-tangix'], static function ($routes) {
// ...
});
// ...
}
); Maybe creating |
To be clear. Is this a bug or bug+regression (it worked fine before 4.5)? IMO collecting all the arguments together and executing them only once is not an option since it may lead to security issues. E.g. Shield filters. However, the current behavior can also be a security issue. The filter should be executed every time it's defined with passed arguments. Using aliases seems like a nice temporary workaround to make filters work as they should. |
Nope... from what I see in the code using aliases will not work. |
Hehe, I'd say bug since after migrating 4.4 -> 4.5 I started exploring with nested groups based on what I learned from reading through the docs after upgrading. My 4.4 code was different. |
Ok, thanks @tangix. It's a little comforting. |
In any case, the docs should be updated regardless because they are misleading/confusing |
In my understanding, this is not a regression. Because
|
Yes, merging filters is probably the only change that happened to filters in v4.5 and it has nothing to do with the issue.
|
FWIW - I've replaced my original code with one Filter having |
I sent PR #8977 to |
I sent PR #8978 to fix |
PHP Version
8.1
CodeIgniter4 Version
4.5.2
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
macOS
Which server did you use?
cli-server (PHP built-in webserver)
Database
No response
What happened?
A route definition containing nested group() statements with filters having the same name doesn't execute all the filters before executing the Controller method.
Steps to Reproduce
Please see https://github.com/tangix/ci45-nested-groups for a complete example.
Check the README.md file for instructions.
Expected Output
If the same filter is defined with different arguments (after the
:
character) the filter should be executed multiple times with the different arguments passed or at least have the multiple arguments passed as an array.Anything else?
No response
The text was updated successfully, but these errors were encountered: