php - yii2生成URL出现405怎么回事
天蓬老师
天蓬老师 2017-04-10 15:28:21
0
1
306

在使用Yii时候出现如下情况,
在模板页面使用退出后台
解析后网页生成的代码的URL地址是 localhost/yii2/backend/index.php?r=site/logout,地址是对的,访问的时候出现如下:
Method Not Allowed (#405) Method Not Allowed. This url can only handle the following request methods: POST. The above error occurred while the Web server was processing your request. Please contact us if you think this is a server error. Thank you.

请问为啥会出现405?哪里配置错了?配置文件里面没有配置路由
通过firebug发现前台的是可以的,而且是POST提交。而通过url生成的访问就不对了?求助

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回覆 (1)
阿神

肯定是配置site/logout这个action的verbs了,提示很明显,这个action只接受通过POST发送的请求!
所以你检查下siteController 下的behaviors 是不是配置了

'verb' => [ 'class' => VerbFilter::className(), 'actions' => [ 'logout' => ['post'], ], ],

如果允许GET访问的话,那么可以改成:

'verb' => [ 'class' => VerbFilter::className(), 'actions' => [ 'logout' => ['get'], //当然可以是是 ['get', 'post'],同时支持POST和GET两种方式访问 ], ],
    最新下載
    更多>
    網站特效
    網站源碼
    網站素材
    前端模板
    關於我們 免責聲明 Sitemap
    PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!