我使用此功能作为注销链接,而不是在菜单上使用它。Yii2注销链接问题
验证码我用:
<?= Html::a('Logout', ['site/logout'], ['data-method' => 'post']) ?>
列明
Method Not Allowed. This url can only handle the following request methods: POST.
我怎样才能解决这个问题呢?
我使用此功能作为注销链接,而不是在菜单上使用它。Yii2注销链接问题
验证码我用:
<?= Html::a('Logout', ['site/logout'], ['data-method' => 'post']) ?>
列明
Method Not Allowed. This url can only handle the following request methods: POST.
我怎样才能解决这个问题呢?
我觉得应该是:
<?= Html::a('Logout', ['site/logout'], ['data' => ['method' => 'post']]) ?>
您还必须确保已加载YiiAsset。这是执行魔术的JS代码(链接通常会产生GET请求)。默认情况下,当您使用Yii项目模板生成了初始代码时,它将包含在AppAsset中,而AppAsset又会在布局文件(AppAsset::register($this);
)中得到实例化。
嗨** robsch **,尚未解决我的问题,显示相同的错误。 –
你的控制器中有动词过滤器吗? – robsch
不,我在我的控制器中没有动词过滤器,但是我添加了这个 - 使用yii \ filters \ VerbFilter;问题仍然存在。 –
[Yii2:方法不允许(#405)注销用户]的重复(http://stackoverflow.com/questions/27420533/yii2-method-not-allowed-405-while-logout-user) – arogachev