1.Controler中需要导入:
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
2.config/web.php
'components' => [
"user"=>[
"loginUrl"=>["login/login"],//跳转到指定的action
]
]
默认是跳转到site/login的
3.Controler中:
public function behaviors(){
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['index', 'create', 'update'],
'rules' => [
// 允许认证用户
[
'allow' => true,
'roles' => ['@'],
],
// 默认禁止其他用户
],