menu_id); $items = $menu->items; return $this->render('menu', [ 'items' => $this->getMenu($items), 'menu' => $menu, ]); } /** * @param $items MenuItem[] * * @return array */ private function getMenu($items, $paren_id = null) { $array = []; foreach ($items as $item) { 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; } }