L
L
Light7772016-01-12 20:28:02
Yii
Light777, 2016-01-12 20:28:02

How to make menu item selected in yii2?

How to make menu items selected on your page
If in "About Us" so that there is li class="" there is li class="selected"
in main.php such menu code

<div class="menu-container clearfix vertical-align-cell">
                        <nav>
                            <ul class="sf-menu">
                                <li class="selected">
                                    <a href="<?=Url::toRoute('/site/index')?>" title="Главная">
                                        ГЛАВНАЯ
                                    </a>
                                </li>
                                <li>
                                    <a href="<?=Url::toRoute('/site/about')?>" title="О НАС">
                                        О НАС
                                    </a>
                                </li>
                                <li>
                                    <a href="<?=Url::toRoute('/site/uslugi')?>" title="УСЛУГИ">
                                        УСЛУГИ
                                    </a>
                                </li>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2016-01-12
@Light777

<li class="<?=(Yii::$app->controller->id == 'site' ? 'selected' : '')?>">
        <a href="<?=Url::toRoute('/site/about')?>" title="О НАС">
            О НАС
        </a>
    </li>

P
pantsarny, 2016-01-14
@pantsarny

Check out the Menu Widget

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question