Answer the question
In order to leave comments, you need to log in
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;
}
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();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question