How to set up Navbar property in Yii2

I have a navigation header as follows:

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="container-fluid"> <div class="navbar-collapse collapse"> <form class="navbar-form navbar-right" role="search"> <div class="form-group has-feedback"> <input id="searchbox" type="text" placeholder="Search" class="form-control"> <span id="searchicon" class="fa fa-search form-control-feedback"></span> </div> </form> </div><!--/.navbar-collapse --> </div> </div> 

I have a problem when I want to convert this code using yii\bootstrap\NavBar; :

 <div class="navbar-collapse collapse"> <form class="navbar-form navbar-right" role="search"> <div class="form-group has-feedback"> <input id="searchbox" type="text" placeholder="Search" class="form-control"> <span id="searchicon" class="fa fa-search form-control-feedback"></span> </div> </form> </div><!--/.navbar-collapse --> 

And this is the code of my Layout using yii\bootstrap\NavBar; :

 <?php NavBar::begin([ 'brandLabel' => 'My Company', 'brandUrl' => Yii::$app->homeUrl, 'options' => [ 'class' => 'navbar navbar-inverse navbar-fixed-top', 'role' => 'navigation', ], ]); NavBar::end(); ?> 

I read the Navbar Widget , but still do not understand. Can anyone teach me how to use the Navbar widget on the Yii2 framework ?

+5
source share
1 answer

Ok, here is the code for this, here I just put the searchbox from what you posted in the question, and I guess you know how echo other menu links in navbar

In any case, it looks like

 <?php NavBar::begin([ 'brandLabel' => 'My Company', 'brandUrl' => Yii::$app->homeUrl, 'options' => [ 'class' => 'navbar navbar-inverse navbar-fixed-top', 'role' => 'navigation', ], ]); $menuItems = [ ['label' => 'Home', 'url' => ['controller url here']], ]; echo Nav::widget([ 'options' => ['class' => 'navbar-nav navbar-right'], 'items' => $menuItems, ]); echo "<form class='navbar-form navbar-right' role='search'> <div class='form-group has-feedback'> <input id='searchbox' type='text' placeholder='Search' class='form-control'> <span id='searchicon' class='fa fa-search form-control-feedback'></span> </div> </form>"; NavBar::end(); ?> 
+4
source

Source: https://habr.com/ru/post/1234612/


All Articles