yii之behaviors
BaseController:
protected $actions = ['*'];
protected $except = [];
protected $mustlogin = [];
protected $verbs = [];
// 行为过滤
public function behaviors()
{
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => $this->actions, // 针对哪些方法有效,默认所有
'except' => $this->except, // 针对哪些方法不进行控制
'rules' => [
[
'allow' => false,
'actions' => empty($this->mustlogin) ? [] : $this->mustlogin,
'roles' => ['?'] // 未登录用户默认均不可访问
],
[
'allow' => true,
'actions' => empty($this->mustlogin) ? [] : $this->mustlogin,
'roles' => ['@'] // 登陆用户默认均可访问
]
]
],
'verbs' => [
'class' => \yii\filters\VerbFilter::className(),
'actions' => $this->verbs, // 针对某些方法限制其访问方式
]
];
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步