E
E
Evgeny Lavrentiev2015-02-17 03:51:35
Yii
Evgeny Lavrentiev, 2015-02-17 03:51:35

Yii2 data-method=post not working?

Can't figure it out already broke my head in view template in widgets Nav added

['label' => 'Выйти', 'url' => ['/core/default/logout'], 'linkOptions' => ['data-method' => 'post'], 'visible' => !\Yii::$app->user->isGuest],

And in the controller in the module added as expected:
'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],

And for example, I'm on the Index page, I press it and 405 comes out, and if I'm on the page, let's say signup works.
Who can tell what is the problem?
exception 'yii\web\MethodNotAllowedHttpException' with message 'Method Not Allowed. This url can only handle the following request methods: POST.' in D:\_osweb_premium\domains\***\vendor\yiisoft\yii2\filters\VerbFilter.php:105
Stack trace:
#0 [internal function]: yii\filters\VerbFilter->beforeAction(Object(yii\base\ActionEvent))
#1 D:\_osweb_premium\domains\***\vendor\yiisoft\yii2\base\Component.php(538): call_user_func(Array, Object(yii\base\ActionEvent))
#2 D:\_osweb_premium\domains\***\vendor\yiisoft\yii2\base\Controller.php(259): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
#3 D:\_osweb_premium\domains\***\vendor\yiisoft\yii2\web\Controller.php(108): yii\base\Controller->beforeAction(Object(yii\base\InlineAction))
#4 D:\_osweb_premium\domains\***\vendor\yiisoft\yii2\base\Controller.php(149): yii\web\Controller->beforeAction(Object(yii\base\InlineAction))
#5 D:\_osweb_premium\domains\***\vendor\yiisoft\yii2\base\Module.php(455): yii\base\Controller->runAction('logout', Array)
#6 D:\_osweb_premium\domains\***\vendor\yiisoft\yii2\web\Application.php(83): yii\base\Module->runAction('core/default/lo...', Array)
#7 D:\_osweb_premium\domains\***\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#8 D:\_osweb_premium\domains\***\web\index.php(18): yii\base\Application->run()
#9 {main}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Terminaft, 2015-02-17
@lavrentiev

jQuery included?

E
Evgeny Lavrentiev, 2015-02-17
@lavrentiev

<?= Html::csrfMetaTags() ?>
Tag added. Yii2 updated!

R
Ruslan Madatov, 2015-09-03
@inginer

How to enable YiiAssets I tried to write in detail toproduction.ru/blog/yii2-data-method-post.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question