M
M
Maybe_V2016-05-31 21:03:52
Yii
Maybe_V, 2016-05-31 21:03:52

How to control display of label on NavBar widget?

I'm making a training blog in yii2!
I have a "My Blog" tab:
8c8606670f8649c89eb9e500a752805f.png
It shows up all the time even when no one is logged in - that's not right!
How can I make this NavBar tab appear only if there is a logged in user on the page ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Krymtsev, 2016-05-31
@krimtsev

check if authorization is present - display the button. if the guest is not.
There is a lot of information about this on google.

A
Alexander N++, 2016-05-31
@sanchezzzhak

Create 2 lists if authorized then the list is like this, if the list is not authorized otherwise.
Yii::$app->user->isGuest

G
Green_Cat, 2016-05-31
@Green_Cat

$menuItems[] = ['label' => ''My posts, 'url' => ' [site]', 'visible' => (!Yii::$app->user->isGuest)];
Then do this Nav::widget(['items' =>$menuItems])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question