menu_id); $items = $menu->items; return $this->render('menu', [ 'items' => $this->getMenu($items), 'menu' => $menu, ]); } /** * @param array $items * @param null $paren_id * @return array */ private function getMenu(array $items, $paren_id = null): array { $array = []; foreach ($items as $item) { /* @var $item MenuItem */ if ($item->parent_id != $paren_id) { continue; } $array[$item->id]['item'] = $item; if ($children = $item->children) { $array[$item->id]['children'] = $this->getMenu($children, $item->id); } } return $array; } }