-
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: route group filter bug #7963
Comments
This note seems to explain if you specify a filter in the outer group, the filter is not merged into the filters in the inner group. |
Oh!! 😭 😭 It's kind of pain. |
But the current behavior is confusing. If we don't set options in the inner group, the outer group options are applied. $routes->group('', ['filter' => 'csrf'], function ($routes) {
$routes->get('dashboard', function (){
echo "CSRF is working";
});
$routes->group('profile', function($routes){
$routes->get('/', function (){
echo "CSRF is working";
});
});
});
If we set options array in the inner group, the outer group options are not applied. $routes->group('', ['filter' => 'csrf'], function ($routes) {
$routes->get('dashboard', function (){
echo "CSRF is working";
});
$routes->group('profile', [], function($routes){
$routes->get('/', function (){
echo "CSRF is not working";
});
});
});
|
@codeigniter4/core-team
|
Dunno, sounds like a bug... even though it's documented. |
I would like to fix as a bug, but the impact may be big. |
Followed up on the PR. |
A small question on the topic. Is it normal that the "filter" option is applied before and after the request? $routes->group('', ['filter' => 'auth'], static function ($routes) {
$routes->get('/expenses', 'Expense::list', ['as' => 'expenses.list']);
}); +--------+--------------------+--------------------+-------------------------------------+----------------+---------------+
| Method | Route | Name | Handler | Before Filters | After Filters |
+--------+--------------------+--------------------+-------------------------------------+----------------+---------------+
| GET | expenses | » | \App\Controllers\Expense::list | auth csrf | auth | |
Yes, it is expected, but probably the auth filter does nothing in |
Good. What will happen if the filter changes something or does more complicated work? |
I sent another PR #8033 |
Hi all, I created two PRs. |
Closed by #8033 |
PHP Version
8.2
CodeIgniter4 Version
4.4.1
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Windows, Linux
Which server did you use?
apache
Database
MySQL 5.6
What happened?
I was using filters in
Grouping Routes
which was working properly innested routes
andnested grouping routes
. But when I used a namespace innested grouping routes
the filter stopped working fornested grouping routes
.Steps to Reproduce
Expected Output
I am expecting the auth filter to be called before the profile request.
Anything else?
No response
The text was updated successfully, but these errors were encountered: