我想将控制器的访问权限限制为只有一个IP(或IP列表)。
配置的正确方法是什么?
(例如,我希望只有IP 172.19.37.175
才能访问index.php?r=painel/restrict
)。
我试过这种方式:
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::classname(),
'only' => ['index'],
'rules' => [
[
'allow' => true,
'roles' => ['?'],
'ips' => ['172.19.37.175'],
],
],
'denyCallback' => function ($rule, $action) {
throw new \Exception('You are not allowed to access this page');
}
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
答案 0 :(得分:4)
变化
'roles' => ['?']
到
'roles' => ['@']