[b]Method Not Allowed (#405 )
Method Not Allowed. This URL can only handle the following request methods: POST. [/b]
The upper error will occurred when i am going to logout from my left sidebar menu (Kartik V Extensions)
I added ‘data-method’ => ‘post’ in $linkOptions
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = [
'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => [
'class' => 'btn btn-link logout',
'data-method' => 'post',
],
];
}
echo SideNav::widget([
'type' => SideNav::TYPE_DEFAULT,
'heading' => 'Parina Koise',
'items' => $menuItems,
]);
I also added the line in controller
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
Please see the screenshot.
7532
Does you registered YiiAsset?
alirz23
(Ali Raza)
November 20, 2017, 3:39pm
3
please do not make duplicate posts if you already have a forum post open for a given issue. did you register yii assets?
<?php
// put this in your layout/view file
\yii\web\YiiAsset::register($this);
Thanks.
OK. I will never post Duplicate.
I put the code in main.php file
link : D:\xampp\htdocs\yii_hoibo\frontend\views\layouts\main.php
<?php
\yii\web\YiiAsset::register($this);
I also try
<?php
YiiAsset::register($this);
But After All Untill Showing
Method Not Allowed (#405 )
Method Not Allowed. This URL can only handle the following request methods: POST.
<?php
/* @var $this \yii\web\View */
/* @var $content string */
//use kartik\widgets\SideNav;
use kartik\sidenav\SideNav;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use frontend\assets\AppAsset;
use common\widgets\Alert;
AppAsset::register($this);
// put this in your layout/view file
\yii\web\YiiAsset::register($this);
?>
When I use
YiiAsset::register($this);
The following image error are showing.
7536
alirz23
(Ali Raza)
November 21, 2017, 11:40am
6
remove the
YiiAsset::register($this)
and
\yii\web\YiiAsset::register($this)
,
I don’t think its related to YiiAsset since you already register AppAsset which requires YiiAsset so that is good.
can you verify you have yii.js file loaded and also your logout links contain data-method="post", you can use the dev tools or view source on the page.
It’s because you have js errors on page. Open browser console.
Thanks.
Whenf I Click for Logout
Then The Following Error Image Showing
I really don’t know how check yii.js file load
logout links contain data-method="post"
Please help.
7537
alirz23
(Ali Raza)
November 21, 2017, 2:37pm
9
just view source and look towards the end of the page, all of your js files should be at the bottom of the page.
jkofsky
(Jkofsky)
November 21, 2017, 9:33pm
10
Does this work if you are on a ‘site’ page? Because this can be used all over the website you may need to add ‘//’ to the beginning of the route array
$menuItems[] = [
'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['//site/logout'],
'linkOptions' => [
'class' => 'btn btn-link logout',
'data-method' => 'post',
],
];
In Yii1, you needed to do this to tell the UrlManager that the route was to start at the root controller. If not added it added it to the current controller.
hakimchamon
(Hakimchamon)
November 21, 2017, 10:29pm
11
I try following code but not work.
$menuItems[] = [
'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['//site/logout'],
'linkOptions' => [
'class' => 'btn btn-link logout',
'data-method' => 'post',
],
];
I can see view source now.
There are yii.js loaded below of the view source.
<script src="/yii_hoibo/frontend/web/assets/c5335b7c/jquery.js"></script>
<script src="/yii_hoibo/frontend/web/assets/a1e44e0b/yii.js"></script>
<script src="/yii_hoibo/frontend/web/assets/2ea6d62d/js/bootstrap.js"></script>
<script src="/yii_hoibo/frontend/web/assets/1407bfc8/js/sidenav.js">
7539
Please tell me need to do now. Thanks.
hakimchamon
(Hakimchamon)
November 22, 2017, 10:26am
12
[b]I find a solutions from another topic discussion.
Please suggest me is it the correct/right way ?
Thanks.[/b]
$menuItems[] = [
'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'template' => '<a href="{url}" data-method="post">{label}</a>',
//'linkOptions' => ['data-method' => 'post']
];