I'm doing on yii2 training blog!

I have a tab "My Blog":

enter image description here

It is displayed constantly even when no one logged in - this is not correct!

How to make the NavBar tab a` only appear if there is a logged in user on the page?

  • See how the Login and Logout display is done and make by analogy - MasterAlex
  • if(Yii::$app->user->isGuest == false) { echo "My blog"; } if(Yii::$app->user->isGuest == false) { echo "My blog"; } something like this - MasterAlex

1 answer 1

If you are doing through the widget, then add next to the label and url another index for this item:

 'visible'=>!Yii::$app->user->isGuest, 

http://www.yiiframework.com/doc-2.0/yii-bootstrap-nav.html