Answer the question
In order to leave comments, you need to log in
Is it correct to use the standard Menu widget in yii2 like this?
I decided to get rid of the bootstrap menu widgets and use a simple yii\widgets\Menu
When I got to the Logout button, I first encountered a problem - items does not accept the values that were written for Nav / NavBar:
$menuItems[] = '<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'Logout (' . Yii::$app->user->identity->username . ')',
['class' => 'btn btn-link']
)
. Html::endForm()
. '</li>';
$menuItems[] = ['label' => 'Выйти('.Yii::$app->user->identity->username.')', 'url' => '/site/logout'];
$menuItems[] = ['label' => Html::beginForm(['/site/logout'], 'post')
. Html::submitButton('Logout ('. Yii::$app->user->identity->username . ')'), 'encode' => false];
'encode' => false
, disabling encode allows you to display the form through the label, and not the code as text. Answer the question
In order to leave comments, you need to log in
[
'label' => 'Выход',
'url' => ['/site/logout'],
'template' => '<a href="{url}" data-method="post">{label}</a>'
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question