How to change NavBar on execution time

Hi comunity…

I need to add or remove complete menu tree from NavBar in execution time depending on some config options I take from DB.

How can I do that?

Yii has a simple ‘visible’ option in the menu. You can query your db for example in the controller, set a session variable, and render the menu. If you’ve got to do it at every action, you can make a basecontroller, where the construction method contains the db query, and inherit every new controller from your basecontroller.




// somewhere before loading the menu, i.e. in the controller

\Yii::$app->session->set('key', false);


// render the menu


echo Menu::widget([

    'items' => [

        

        ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->session->get('key')],

    ],

]);



I tried the Visible option and works well.

Thanks a lot.