Skip to content

Instantly share code, notes, and snippets.

@63phc
Created October 24, 2016 05:38
Show Gist options
  • Save 63phc/fac2c1e01bb8c80df589811c64f82d3e to your computer and use it in GitHub Desktop.
Save 63phc/fac2c1e01bb8c80df589811c64f82d3e to your computer and use it in GitHub Desktop.
public function run()
{
$categories = Category::find()->published()->orderBy('id ASC')->all();
// Рендерим представление
echo $this->render('category', [
'categories' => $categories,
'title' => $this->title,
'menuItems' => $this->getMenuItems($categories)
]);
}
private function getMenuItems($categories, $activeId = null, $parent = null)
{
$menuItems = [];
foreach ($categories as $category) {
if ($category->parent_id === $parent) {
$menuItems[$category->id] = [
'active' => $activeId === $category->id,
'label' => $category->title,
'url' => ['/catalog/default/list', 'slug' => $category->slug],
'items' => $this->getMenuItems($categories, $activeId, $category->id),
];
}
}
return $menuItems;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment