Нужно что бы с сылками выгружались картинки каждого пункта меню
view:
<?php
echo Menu::widget([
'menuKey' => '1',
'options' => [
'id'=>'navid',
'class' => 'nav spacer',
'data'=>'menu',
],
'linkTemplate' => '<nav class="nav spacer"><a href="{url}">{image}{label}</a></nav>',
'activeCssClass'=>'active',
'encodeLabels' =>'false',
'itemOptions' => ['class' => 'nav__link'],
'submenuTemplate' => "<ul class = 'droplink active open dropdown-menu' role = 'menu'> \ n {items} \ n </ul>",
]);
?>
wigjet :
<?php
namespace frontend\widgets;
class Menu extends \yii\widgets\Menu
{
/**
* @var integer|null $menuKey Ключ используемого меню для построения структуры в $items
*/
public $menuKey;
/**
* {@inheritdoc}
*/
public function run()
{
if (!empty($this->menuKey)) {
$this->loadItems();
}
return parent::run();
}
/**
* @return void
*/
protected function loadItems()
{
if (!empty($this->menuKey)) {
$this->items = [];
$menu = \common\models\Menu::find()
->active()
->andWhere(['key' => $this->menuKey])
->one()
;
if (empty($menu)) {
return;
}
foreach ($menu->getItems()
->active()
->roots()
->orderBy(['order' => SORT_ASC])
->all()
as $item) {
$this->items[] = $this->getMenuItemTree($item);
}
}
}
/**
* @param \common\models\MenuItem $item
* @return array
*/
protected function getMenuItemTree(\common\models\MenuItem $item)
{
$tree = ['label' => $item->label, 'url' => $item->url, 'image'=>$item->image];
$children = $item->getChildren()
->active()
->orderBy(['order' => SORT_ASC])
->all()
;
if (!empty($children)) {
$childTree = [];
foreach ($children as $child) {
$childTree[] = $this->getMenuItemTree($child);
}
$tree['items'] = $childTree;
}
return $tree;
}
}