Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GhostMenu usage not clear #40

Closed
FreezeS opened this issue Apr 8, 2015 · 8 comments
Closed

GhostMenu usage not clear #40

FreezeS opened this issue Apr 8, 2015 · 8 comments

Comments

@FreezeS
Copy link

FreezeS commented Apr 8, 2015

Hello,

I'm trying to use the GhostMenu widget as a navbar in the main layout but the layout is wrong.

I replaced the old navbar with calls to NavBar::begin(), echo GhostMenu::widget..., NavBar::end().

Maybe I'm missing something from the documentation but it should be updated to clarify this issue.

@webvimark
Copy link
Owner

Hi, use GhostNav =)

@FreezeS
Copy link
Author

FreezeS commented Apr 8, 2015

No effect, looks exactly the same.
This is my layout:

<?php
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use yii\widgets\Menu;
use app\assets\AppAsset;
use webvimark\modules\UserManagement\components\GhostMenu;
use webvimark\modules\UserManagement\components\GhostNav;
use webvimark\modules\UserManagement\UserManagementModule;

/* @var $this \yii\web\View */
/* @var $content string */

AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
</head>
<body>

<?php $this->beginBody() ?>
    <div class="wrap">
        <?php



//            NavBar::begin([
//                'brandLabel' => 'My Company',
//                'brandUrl' => Yii::$app->homeUrl,
//                'options' => [
//                    'class' => 'navbar-inverse navbar-fixed-top',
//                ],
//            ]);
//            echo Nav::widget([
//                'options' => ['class' => 'navbar-nav navbar-right'],
//                'items' => [
//                    ['label' => 'Home', 'url' => ['/site/index']],
//                    ['label' => 'About', 'url' => ['/site/about']],
//                    ['label' => 'Contact', 'url' => ['/site/contact']],
//                    Yii::$app->user->isGuest ?
//                        ['label' => 'Login', 'url' => ['/site/login']] :
//                        ['label' => 'Logout (' . Yii::$app->user->identity->username . ')',
//                            'url' => ['/site/logout'],
//                            'linkOptions' => ['data-method' => 'post']],
//                ],
//            ]);
//            
//            
//            
//            NavBar::end();



        ?>


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

            echo GhostMenu::widget([
                'encodeLabels'=>false,
                'activateParents'=>true,

                'items' => [
                    [
                        'label' => 'Backend routes',
                        'items'=>UserManagementModule::menuItems()
                    ],
                    [
                        'label' => 'Frontend routes',                                    
                        'items'=>[
                            ['label'=>'Login', 'url'=>['/user-management/auth/login']],
                            ['label'=>'Logout', 'url'=>['/user-management/auth/logout']],
                            ['label'=>'Registration', 'url'=>['/user-management/auth/registration']],
                            ['label'=>'Change own password', 'url'=>['/user-management/auth/change-own-password']],
                            ['label'=>'Password recovery', 'url'=>['/user-management/auth/password-recovery']],
                            ['label'=>'E-mail confirmation', 'url'=>['/user-management/auth/confirm-email']],
                        ],
                    ],
                ],

            ]);

            GhostNav::end();

        ?>

        <div class="container">
            <?= Breadcrumbs::widget([
                'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
            ]) ?>
            <?= $content ?>
        </div>

    </div>

    <footer class="footer">
        <div class="container">
            <p class="pull-left">&copy; My Company <?= date('Y') ?></p>
            <p class="pull-right"><?= Yii::powered() ?></p>
        </div>
    </footer>

<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>

@webvimark
Copy link
Owner

It should be like this

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

            echo GhostNav::widget([
                'encodeLabels'=>false,
                'activateParents'=>true,

                'items' => [
                    [
                        'label' => 'Backend routes',
                        'items'=>UserManagementModule::menuItems()
                    ],
                    [
                        'label' => 'Frontend routes',                                    
                        'items'=>[
                            ['label'=>'Login', 'url'=>['/user-management/auth/login']],
                            ['label'=>'Logout', 'url'=>['/user-management/auth/logout']],
                            ['label'=>'Registration', 'url'=>['/user-management/auth/registration']],
                            ['label'=>'Change own password', 'url'=>['/user-management/auth/change-own-password']],
                            ['label'=>'Password recovery', 'url'=>['/user-management/auth/password-recovery']],
                            ['label'=>'E-mail confirmation', 'url'=>['/user-management/auth/confirm-email']],
                        ],
                    ],
                ],

            ]);

            NavBar::end();

        ?>

@FreezeS
Copy link
Author

FreezeS commented Apr 8, 2015

Ok, now it resembles a menu:

selection_029

Is that how it's supposed to look?

@webvimark
Copy link
Owner

OK, GhostNav is just the same Nav widget. Only thing it does is hiding links that is unavailable for current user.

If you want bootstrap menu, then do the following:

  1. start from basic Yii2 example
  2. replace Nav with GhostNav
  3. Add links that you want to see in your menu

@FreezeS
Copy link
Author

FreezeS commented Apr 8, 2015

Ok, I thought it will make two properly stylized drop-down menus.
I'll see what I can do next.
Thanks for the help :)

@webvimark
Copy link
Owner

You are welcome =)

@brama051
Copy link

brama051 commented Jun 13, 2016

@FreezeS
add widget options 'options' => ['class' => 'navbar-nav navbar-right'],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants