Created
October 24, 2016 05:38
-
-
Save 63phc/fac2c1e01bb8c80df589811c64f82d3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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