mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-20 16:38:22 +08:00
Merge pull request #2077 from lucianobaraglia/authorization-doc-update
Authorization doc match callback example
This commit is contained in:
@@ -57,10 +57,10 @@ class SiteController extends Controller
|
|||||||
return [
|
return [
|
||||||
'access' => [
|
'access' => [
|
||||||
'class' => \yii\web\AccessControl::className(),
|
'class' => \yii\web\AccessControl::className(),
|
||||||
'only' => ['special'],
|
'only' => ['special-callback'],
|
||||||
'rules' => [
|
'rules' => [
|
||||||
[
|
[
|
||||||
'actions' => ['special'],
|
'actions' => ['special-callback'],
|
||||||
'allow' => true,
|
'allow' => true,
|
||||||
'matchCallback' => function ($rule, $action) {
|
'matchCallback' => function ($rule, $action) {
|
||||||
return date('d-m') === '31-10';
|
return date('d-m') === '31-10';
|
||||||
@@ -68,6 +68,17 @@ class SiteController extends Controller
|
|||||||
],
|
],
|
||||||
```
|
```
|
||||||
|
|
||||||
|
And the action:
|
||||||
|
|
||||||
|
```php
|
||||||
|
// ...
|
||||||
|
// Match callback called! This page can be accessed only each October 31st
|
||||||
|
public function actionSpecialCallback()
|
||||||
|
{
|
||||||
|
return $this->render('happy-halloween');
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Sometimes you want a custom action to be taken when access is denied. In this case you can specify `denyCallback`.
|
Sometimes you want a custom action to be taken when access is denied. In this case you can specify `denyCallback`.
|
||||||
|
|
||||||
Role based access control (RBAC)
|
Role based access control (RBAC)
|
||||||
|
|||||||
Reference in New Issue
Block a user