You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once configured, you can use the `can()` method to check if a user has permission to perform certain actions:
210
+
211
+
```php
212
+
$user->can('acrticles,read');
213
+
```
214
+
215
+
**(2) Behaviors**
216
+
217
+
The `PermissionControl` behavior allows you to enforce permission checks at the controller level. Add the PermissionControl behavior to your controller's behaviors() method:
'user' => $user, // optional, defaults to \Yii::$app->user
226
+
'only' => ['read-articles', 'write-articles'],
227
+
'policy' => [
228
+
[
229
+
'allow' => true,
230
+
'actions' => ['read-articles'],
231
+
'enforce' => ['articles', 'read']
232
+
],
233
+
[
234
+
'allow' => true,
235
+
'actions' => ['write-articles'],
236
+
'enforce' => ['articles', 'write']
237
+
]
238
+
],
239
+
'denyCallback' => function ($policy, $action) {
240
+
// custom action when access is denied
241
+
} // optional, defaults to throwing an exception
242
+
]
243
+
];
244
+
}
245
+
```
246
+
247
+
**Note:** Additionally,You can also configure a `denyCallback` for each `policy`, which will be invoked when the user does not meet the required permission. This callback takes precedence. The configuration is similar to Yii's official [AccessControl](https://www.yiiframework.com/doc/guide/2.0/zh-cn/security-authorization#access-control-filter).
248
+
191
249
See [Casbin API](https://casbin.org/docs/en/management-api) for more APIs.
0 commit comments