A
A
agent11562017-01-13 14:20:32
Yii
agent1156, 2017-01-13 14:20:32

Working with aliases and navbar?

I created an alias that leads to the backend. If I write it in the link, then everything works, but if in the navbar, then the alias value is simply added after index? How to add a link to the navbar?

<?php
    NavBar::begin([
        'brandLabel' => 'My Company',
        'brandUrl' => Yii::$app->homeUrl,
        'options' => [
            'class' => 'navbar-inverse navbar-fixed-top',
        ],
    ]);
    $menuItems = [
        ['label' => Yii::t('app', 'Главная'), 'url' => ['/site/index']],
        ['label' => 'ALANÆ LIFE', 'url' => ['/site/life']],   <----------------!!!!!!!!!!!!!!!!!!!!!
        ['label' => Yii::t('app','FABRIC'), 'url' => ['/site/fabric']],
        ['label' => 'ALANÆ HOME', 'url' => ['/site/alaniahome']],
        ['label' => 'АТЕЛЬЕ', 'url' => ['/backend/site/contact']],
            ['label' => 'ОБ ALANÆ', 'url' => ['@backend']],
                ['label' => 'ВАКАНСИИ', 'url' => ['/site/contact']],
            ];
    if (Yii::$app->user->isGuest) {
        $menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];   <----------------!!!!!!!!!!!!!!!!!!!!!
        $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
    } else {
        $menuItems[] = '<li>'
            . Html::beginForm(['/site/logout'], 'post')
            . Html::submitButton(
                'Logout (' . Yii::$app->user->identity->username . ')',
                ['class' => 'btn btn-link']
            )
            . Html::endForm()
            . '</li>';
    }
    echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-right'],
        'items' => $menuItems,
    ]);
    NavBar::end();
    ?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-01-13
@slo_nik

Good afternoon.
Try using helper Url and its to() and toRoute() methods

M
Maxim Timofeev, 2017-01-13
@webinar

I created an alias that leads to the backend

where is the code? how did you create it? Usually alies in yii2 is a path and not a url,
but if there is still a line with a url, then perhaps like this:
['label' => 'ОБ ALANÆ', 'url' => Yii::getAlias('@backend')],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question