Answer the question
In order to leave comments, you need to log in
How to set the active menu item class to Nav::widget?
There is a table in the database that populates the items array in Nav. Pages that have template_name specified have an Article controller and a default index method.
+----+------------------------------+-----------+---------------+---------------+
| id | title | type | url | template_name |
+----+------------------------------+-----------+---------------+---------------+
| 5 | О фабрике | page | /about | article |
| 6 | Новинки | page | /products/new | main |
| 7 | Каталог | container | /catalog | main |
| 8 | Сотрудничество | page | /partners | article |
| 9 | Мастерская | page | /master_class | main |
| 10 | Новости | container | /news | main |
| 11 | Контакты | page | /contacts | main |
+----+------------------------------+-----------+---------------+---------------+
'rules' => [
'/about' => 'article/index',
'/partners' => 'article/index',
],
Answer the question
In order to leave comments, you need to log in
Your problem is related to the fact that by default the Nav widget takes the current route from the controller that is called and without considering the url rules. You can solve this problem by setting the route for Nav yourself, like this:
<?= Nav::widget([
'route' => Yii::$app->getRequest()->pathInfo,
'items' => $items
]);
I think at least it should be like this:
'rules' => [
'/<url>' => 'article/index',
],
public function actionIndex($url){
return $this->render('some_view',[
'model' => SomeModel::findOne(['url'=>$url]);
]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question