-
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
Request: Bulk route filters with parameters #2078
Comments
I think I was able to accomplish what I wanted with the following:
... but I'm going to leave this here until a few more eyes have seen it just in case. UPDATE: This doesn't work. It runs the filters correctly on the route but then fails to match to the expected controller. This line from the User Guide made me think I could use dynamic controller routing:
... but maybe it doesn't work like that? |
I'm trying to add filters similar to what you are doing to staff routes. It seems as if the filter doesn't take when it's in the Config/Routes.php file like this: $routes->group('staff', [
'namespace' => 'Staff\Controllers',
'filter' => 'permissions:access_staff'
], function($routes)
{
// Routes listed here
}); I tried removing the parameters and just left it as public $aliases = [
'csrf' => \CodeIgniter\Filters\CSRF::class,
// 'toolbar' => \CodeIgniter\Filters\DebugToolbar::class,
'honeypot' => \CodeIgniter\Filters\Honeypot::class,
'auth' => \App\Filters\Auth::class,
'permissions' => \App\Filters\Permissions::class,
'roles' => \App\Filters\Roles::class
]; I added the alias for permissions and inside that filter class, I have a simple public $filters = [
'permissions' => [
'before' => ['v1/staff/*']
]
]; It hits the var_dump line. However, I can't add parameters to it like this: public $filters = [
'permissions:access_staff' => [
'before' => ['v1/staff/*']
]
]; It doesn't hit the filter :( In the Controller Filters part of the User Guide, it says we can pass parameters. Is this not the case? This is a pretty much necessary functionality of a Filter. I would hate to create a filter for EACH permission. |
That's the essence of one resolution for this request, to allow parameters from Filters.php. Currently they are not supported, as you latter test exhibits. Your first approach looks like it should work fine. Make sure your namespaces and URIs are all matching correctly (e.g. your route group matches on "staff*" whereas your global filter matches "v1/staff/*"). |
Ah okay. $routes->group('{locale}/v1', function($routes) {
// All routes are wrapped inside this
}); |
Rhis should be discussed/resolved on the forum before showing up here. |
Dynamic controller routing indeed does not seem to work. Here, I'm not sure if this is intended behavior, however, I simply dodged this issue by inserting |
So this works, i tried this before the routes does not exists :( |
Bro you are a genius, i don't know how you did that, it is working, i had to rewrite all my controllers with first letter lowercase because all my urls are with lowercase, this is working amazingly. |
@crustamet : Please keep in mind that this is a change in the core files, so it will be reverted when updating CI and it also might not be intended behavior. So I would wait for someone official to comment on this. |
The current thread is a hijack for a different issue. If there is a bug please open a new issue report. Feature Requests should be opened on the forums for discussion and then linked here if deemed appropriate. Please keep conversations on this topic to route filters. FWIW dynamic Controller auto-routing was considered a security issue so intentionally is not allowed. |
Currently route filters can be applied in two places:
$globals
,$methods
, or with URI patterns in$filters
['filter' => 'role:admin']
I would like to be able to use the versatility of URI patterns with filter parameters, but currently these are mutually-exclusive features. Entries in Filters.php cannot take parameters and Routes.php doesn't support filter options for non-specified routes. Using route groups we can apply a filter to any specified routes, e.g.:
... but this requires that all routes be listed explicitly rather than allowing auto-routing.
I would like to see either (or both):
The text was updated successfully, but these errors were encountered: