R
R
Rustam Akimov2016-12-23 07:24:19
Yii
Rustam Akimov, 2016-12-23 07:24:19

How to add a new menu item for a guest?

In the menu widget in the basic YII2 template, there is a check for a guest and if you are a guest, the Login item is displayed, but how to add more items?

Yii::$app->user->isGuest ? (
['label' => 'Вход' ,  'url' => ['/site/login']]
//как вставить еще один пункт сюда
) : ()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Karavaev, 2016-12-23
@Inogami

Don't use ternary operator?

if (Yii::$app->user->isGuest) {
    $menu[] = ['label' => 'Вход' ,  'url' => ['/site/login']];
    $menu[] = ['label' => 'Регистрация' ,  'url' => ['/site/signup']];
    ...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question