E
E
evgenii_k2016-02-05 19:12:11
Yii
evgenii_k, 2016-02-05 19:12:11

Yii2 Nav::widget not working everywhere, how to fix it?

Nav::wiwget to be in layouts for it in the model made a function that collects an array of items

public static function getItems()
    {
        $items = [];
        $models = Category::find()->orderBy('name')->all();
          foreach($models as $category)
        {
            $items[] =[
      'label' => $category->name,
            'url' => '/web/index.php?r=video&category='.$category->id];
        }
            return $items;
    }

Further in layouts/main.php I output
NavBar::begin([
        'brandLabel' => 'My Company',
        'brandUrl' => Yii::$app->homeUrl,
        'options' => [
            'class' => 'navbar-inverse navbar-fixed-top',
        ],
    ]);

 echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-left'],
        'items' => [
            ['label' => 'Категории', 'items' => Category::getItems()],
           ],
    ]);

 NavBar::end();

It works only on SiteController when I go through the same list to another link and from there I try to call a drop-down list, it does not react, but add # to the url and that's it.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question