1 回答
TA贡献1772条经验 获得超6个赞
有几种类型的配置:
1) 使用主要配置阻止对整个应用程序(ak 后端)的访问:
// ../config/main.php
return [
// ...
'components' => [
// ...
],
'as access' => [
'class' => yii\filters\AccessControl::class,
'except' => ['site/error', 'site/login', 'site/logout'],
'rules' => [
['allow' => true, 'roles' => ['@']],
],
],
];
2)通过扩展抽象控制器类来阻止对特定控制器的访问
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
]
];
}
}
现在你可以在你的控制器中扩展这个控制器
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 关注
- 118 浏览
添加回答
举报