E
E
Elios2015-11-07 12:25:05
Yii
Elios, 2015-11-07 12:25:05

How to extend yii2 widget class?

With a banal layout, I often run into the missing properties of standard yii2 widgets, what should I do in such cases?
For example, there is a Menu widget

use yii\widgets\Menu;
  echo Menu::widget([
    'items' => $menuItems,
    'itemOptions' => [
        'class' => 'parent_li',
    ],
          'submenuTemplate' => "<ul class=\"sub_menu\">{items}</ul>",
  ]);

This results in:
<ul>
  <li class="parent_li"><a href="/menu">Родительский элемент</a>
    <ul class="sub_menu">
      	<li class="parent_li"><a href="/sub_menu?id=2">Элемент под меню</a></li>
      <li class="parent_li"><a href="/sub_menu?id=3">Элемент под меню</a></li>
    </ul>
  </li>
</ul>

I need to define a class only for the parent li list, but not for li from sub_menu, I did not find a property that does this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2015-11-07
@strelov1

create your own widget, inherit from yii\widgets\Menu and add

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question