0
我是yii的新手,我试图用站点控制器中的默认行为功能创建一个简单的身份验证。为什么yii2想通过post方法注销
做的时候,我可以登录,但不能注销,并显示错误:
Method Not Allowed. This url can only handle the following request methods: POST.
然后我检查了控制器,发现:
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
我改变了
'actions' => [
'logout' => ['post'],
],
至
'actions' => [
'logout' => ['get'],
],
它工作得很好。
我不知道这背后的概念是什么,为什么会希望使用post方法注销。