title: yii2 navbar with dropdown
body: <p>After some simple edit on the default navbar, I got the code for the menu below... It would be very ugly if I add more menus.</p>
  
  <pre><code>&lt;?php
              NavBar::begin([
                  'brandLabel' =&gt; 'My Project',
                  'brandUrl' =&gt; Yii::$app-&gt;homeUrl,
                  'options' =&gt; [
                      'class' =&gt; 'navbar-inverse navbar-fixed-top',
                  ],
              ]);
              $menuItems = [
                  ['label' =&gt; 'Home', 'url' =&gt; ['/site/index']],
                  ['label' =&gt; 'Contact', 'url' =&gt; ['/site/contact'],'visible'=&gt;false],
              ];
              if (Yii::$app-&gt;user-&gt;isGuest) {
                  $menuItems[] = ['label' =&gt; 'Signup', 'url' =&gt; ['/site/signup']];
                  $menuItems[] = ['label' =&gt; 'Login', 'url' =&gt; ['/site/login']];
              } else {
  
                  if(yii::$app-&gt;user-&gt;can('admin')){
                  $menuItems[] = ['label' =&gt; 'Users', 'url' =&gt; ['/users']];
                  }
  
                  $menuItems[] = ['label' =&gt; 'BUB Sub Projects', 'url' =&gt; ['/bub']];
                  $menuItems[] = ['label' =&gt; 'Incoming BUB', 'url' =&gt; ['/bubincoming']];
                  $menuItems[] = [
                      'label' =&gt; 'Logout (' . Yii::$app-&gt;user-&gt;identity-&gt;username . ')',
                      'url' =&gt; ['/site/logout'],
                      'linkOptions' =&gt; ['data-method' =&gt; 'post']
                  ];
  
              }
              echo Nav::widget([
                  'options' =&gt; ['class' =&gt; 'navbar-nav navbar-right'],
                  'items' =&gt; $menuItems,
              ]);
              NavBar::end();
  
          ?&gt;
  </code></pre>
  
  <p>How to add a dropdown or submenus to any of the menu?</p>