A header widget has been created in the common / widget folder where this code is

<li><a href="<?= Yii::$app->urlManager->createUrl(['/site/logout']) ?>" data-method="post" ><i class="fa fa-sign-out"></i><?=Yii::t('app','LOGOUT');?></a></li> 

tried and so

 <?= Html::a('<i class="fa fa-sign-out"></i>'.Yii::t('app','LOGOUT'),Url::to(['/site/logout']),['data-method'=>'post']); ?> 

These are the assets in the front end

 <?php /** * @link http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ */ namespace frontend\assets; use yii\web\AssetBundle; /** * @author Qiang Xue <qiang.xue@gmail.com> * @since 2.0 */ class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ ... ]; public $js = [ ... ]; public $depends = [ 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', ]; } 

and two

 <?php /** * @link http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ */ namespace frontend\assets; use yii\web\AssetBundle; /** * @author Qiang Xue <qiang.xue@gmail.com> * @since 2.0 */ class IndexAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ ... ]; public $js = [ ... ]; public $depends = [ 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', ]; } 

I try to work loguot I get this answer Method Not Allowed. This url can only handle the following request methods: POST. Method Not Allowed. This url can only handle the following request methods: POST. Why should I do that?

  • What version of YII2 (for 2.0.4 there is a bug: github.com/yiisoft/yii2/issues/8419 ) and is jquery connected on the client side? - Dmitry Nevzorov
  • @DmitryNevzorov version 2.0.7 <script src = "/ assets / 6ee2cdb7 / jquery.js"> is it? - Sergalas
  • Is there a / site / logout path? Yii::$app->urlManager->createUrl(['/site/logout']) assumes that the link will lead to / site / logout / - is there no error here? If jquery really connects, then looking at the assets, nothing can be said - here the controller code is needed, it seems. Check if jquery works? If yes, then the reason is not in assets. - Dmitry Nevzorov

0