From ff6527ca7dce076cc596741645bcc5dad815e1e3 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 19 Jan 2023 16:48:14 +0900 Subject: [PATCH] docs: remove unsupported code sample $filters cannot set filer aruguments. --- docs/authorization.md | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/docs/authorization.md b/docs/authorization.md index 6d3d5e20e..977884adc 100644 --- a/docs/authorization.md +++ b/docs/authorization.md @@ -9,7 +9,6 @@ - [can()](#can) - [inGroup()](#ingroup) - [hasPermission()](#haspermission) - - [Authorizing via Filters](#authorizing-via-filters) - [Authorizing via Routes](#authorizing-via-routes) - [Managing User Permissions](#managing-user-permissions) - [addPermission()](#addpermission) @@ -130,28 +129,34 @@ if (! $user->hasPermission('users.create')) { } ``` -#### Authorizing via Filters +#### Authorizing via Routes -You can restrict access to multiple routes through a [Controller Filter](https://codeigniter.com/user_guide/incoming/filters.html). One is provided for both restricting via groups the user belongs to, as well as which permission they need. The filters are automatically registered with the system under the `group` and `permission` aliases, respectively. You can define the protections within **app/Config/Filters.php**: +You can restrict access to a route or route group through a +[Controller Filter](https://codeigniter.com/user_guide/incoming/filters.html). -```php -public $filters = [ - 'group:admin,superadmin' => ['before' => ['admin/*']], - 'permission:users.manage' => ['before' => ['admin/users/*']], -]; -``` +One is provided for restricting via groups the user belongs to, the other +is for permission they need. The filters are automatically registered with the +system under the `group` and `permission` aliases, respectively. -#### Authorizing via Routes - -The filters can also be used on a route or route group level: +You can set the filters within **app/Config/Routes.php**: ```php $routes->group('admin', ['filter' => 'group:admin,superadmin'], static function ($routes) { - $routes->resource('users'); + $routes->group( + '', + ['filter' => ['group:admin,superadmin', 'permission:users.manage']], + static function ($routes) { + $routes->resource('users'); + } + ); }); - ``` +Note that the options (`filter`) passed to the outer `group()` are not merged with the inner `group()` options. + +> **Note** If you set more than one filter to a route, you need to enable +> [Multiple Filters](https://codeigniter.com/user_guide/incoming/routing.html#multiple-filters). + ## Managing User Permissions Permissions can be granted on a user level as well as on a group level. Any user-level permissions granted will