1 回答

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超6個(gè)贊
有幾種類型的配置:
1) 使用主要配置阻止對(duì)整個(gè)應(yīng)用程序(ak 后端)的訪問(wèn):
// ../config/main.php
return [
// ...
'components' => [
// ...
],
'as access' => [
'class' => yii\filters\AccessControl::class,
'except' => ['site/error', 'site/login', 'site/logout'],
'rules' => [
['allow' => true, 'roles' => ['@']],
],
],
];
2)通過(guò)擴(kuò)展抽象控制器類來(lái)阻止對(duì)特定控制器的訪問(wèn)
use yii\filters\AccessControl;
use yii\web\Controller;
/**
* AbstractSecured controller
*/
abstract class AbstractSecuredController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::class,
// ...
// rules
]
];
}
}
現(xiàn)在你可以在你的控制器中擴(kuò)展這個(gè)控制器
use yii\helpers\ArrayHelper;
/**
* MyNonPublic controller
*/
class MyNonPublicController extends AbstractSecuredController
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return ArrayHelper::merge(
parent::behaviors(),
[
// ...
// controller specific behaviors
// you can even rewrite access behavior config
]
);
}
}
3)你也可以配置ACL
- 1 回答
- 0 關(guān)注
- 164 瀏覽
添加回答
舉報(bào)