5

I used this function for logout link instead of using it on menu.

this code I used:

<?= Html::a('Logout', ['site/logout'], ['data-method' => 'post']) ?>

Showing-

Method Not Allowed. This url can only handle the following request methods: POST.

How can i solve this issue?

fool-dev
  • 7,671
  • 9
  • 40
  • 54
  • 3
    Possible duplicate of [Yii2: Method Not Allowed (#405) while logout user](http://stackoverflow.com/questions/27420533/yii2-method-not-allowed-405-while-logout-user) – arogachev Oct 14 '15 at 06:07

1 Answers1

6

I think it should be:

<?= Html::a('Logout', ['site/logout'], ['data' => ['method' => 'post']]) ?>

See method doc and parameter detail.

You also have to make sure that the YiiAsset was loaded. This is the JS code that does the magic (links are usually producing GET requests). By default when you have generated your initial code with the Yii project templates it gets included with the AppAsset which in turn gets instanciated in the layout file (AppAsset::register($this);).

robsch
  • 9,358
  • 9
  • 63
  • 104