Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Container-fluid in navbar yii2

I am starting learning yii2,

I want to create layout like this : http://www.yiiframework.com/doc-2.0/ext-bootstrap-index.html

I am little confused, how yii write the bootstrap nav. I want to create nav to container-fluid. I have a write in html on codeigniter like this :

<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="<?php echo site_url('admin'); ?>"><i class="fa fa-home"></i> <?php echo $this->config->item('erp_title'); ?></a>
    </div>
    <div id="navbar" class="collapse navbar-collapse">
        <ul class="nav navbar-nav navbar-left">
            <li><a href="#"><i class="fa fa-spinner fa-spin"></i> Export</a></li>
            <li><a href="#"><i class="fa fa-anchor"></i> Import</a></li>
            <li><a href="#"><i class="fa fa-archive"></i> Inventory</a></li>
            <li><a href="#"><i class="fa fa-gavel"></i> Operation</a></li>
            <li><a href="#"><i class="fa fa-money"></i> Marketing</a></li>

            <li><a href="#"><i class="fa fa-money"></i> Keuangan </a></li>
            <li><a href="#"><i class="fa fa-money"></i> Accounting </a></li>
            <li><a href="#"><i class="fa fa-pencil"></i> Persum </a></li>
            <li><a href="#"><i class="fa fa-ship"></i> Armada</a></li>
            <li><a href="#"><i class="fa fa-laptop"></i> IT</a></li>

        </ul>

        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-user"></i> <?php print_r($this->ion_auth->user()->row()->username); ?> <span class="caret"></span></a>
                <ul class="dropdown-menu" role="menu">
                    <?php
                    if ($this->ion_auth->is_admin()) {
                        ?>
                        <li><a href="<?php echo site_url('admin/groups'); ?>">Groups</a></li>
                        <li><a href="<?php echo site_url('admin/users'); ?>">Users</a></li>
                    <?php } ?>

                    <li><a href="<?php echo site_url('admin/user/profile'); ?>">Profile page</a></li>
                    <li class="divider"></li>
                    <li><a href="<?php echo site_url('admin/user/logout'); ?>">Logout</a></li>
                </ul>

            </li>

        </ul>
    </div><!--/.nav-collapse -->
</div>

How to create navbar to container-fluid in yii2 ?

like image 841
Fadly Dzil Avatar asked Aug 18 '16 14:08

Fadly Dzil


2 Answers

The correct way to make the container fluid is to adjust your Navbar's configuration in your NavBar::begin declaration like so:

NavBar::begin([
   'innerContainerOptions' => ['class' => 'container-fluid'],
]);
like image 76
Mark Cross Avatar answered Nov 13 '22 04:11

Mark Cross


You can use:

use yii\bootstrap\NavBar;
use yii\bootstrap\Nav;



NavBar::begin([
        'brandLabel' => 'NavBar Test',
        'innerContainerOptions' => ['class' => 'container-fluid'],
        'brandUrl' => Yii::$app->homeUrl,
        'options' => [
        'class' => 'navbar-inverse',
    ],
]);
echo Nav::widget([
    'options' => ['class' => 'navbar-nav navbar-right'],
    'items' => [
        ['label' => 'Home', 'url' => ['/site/index']],
        ['label' => 'About', 'url' => ['/site/about']],
    ],
]);
NavBar::end();

enter link description here

also for menu only:

use yii\widgets\Menu;

echo Menu::widget([
    'items' => [
        // Important: you need to specify url as 'controller/action',
        // not just as 'controller' even if default action is used.
        ['label' => 'Home', 'url' => ['site/index']],
        // 'Products' menu item will be selected as long as the route is 'product/index'
        ['label' => 'Products', 'url' => ['product/index'], 'items' => [
            ['label' => 'New Arrivals', 'url' => ['product/index', 'tag' => 'new']],
            ['label' => 'Most Popular', 'url' => ['product/index', 'tag' => 'popular']],
        ]],
        ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest],
    ],
]);

enter link description here

like image 1
user206 Avatar answered Nov 13 '22 02:11

user206