S
S
Sergey Beloventsev2016-05-23 13:11:19
Yii
Sergey Beloventsev, 2016-05-23 13:11:19

data-method="post" not working?

in the common/widget folder, a header widget was created where there is this code

<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 that too
<?= 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 frontend
<?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 <[email protected]>
 * @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 <[email protected]>
 * @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 out loguot, I get such a response Method Not Allowed. This url can only handle the following request methods: POST. Why and what am I doing so?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Arutyunov, 2016-05-23
@Sergalas

Example from advanced: https://github.com/yiisoft/yii2-app-advanced/blob/...
You must have a form to make a post request.
See how it looks in the advanced application after rendering (open the page and ctrl+u, see what html is generated by this php code in the source code).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question