Попробовал еще один виджет
execut/yii2-widget-bootstraptreeview, однако всё равно остановился на kartik-sidenav.
Похожий вопрос:
В чем ошибка при построении nested sets menu Yii2?public static function getTree($categories, $left = 0, $right = null, $depth = 1){
$tree = [];
foreach ($categories as $index => $category) {
if ($category->lft >= $left + 1 && (is_null($right) || $category->rgt <= $right) && $category->depth == $depth) {
$tree[$index] = [
'label' => $category->name,
'url' => '/shop/catalog/root?id='.$category->id,
'items' => self::getTree($categories, $category->lft, $category->rgt, $category->depth+1),
];
}
}
return $tree;
}
public static function getFullTreeStructure(){
$roots = self::find()->roots()->addOrderBy('root, lft')->all();
$tree = [];
foreach ($roots as $root){
$tree [] = [
'label' => $root->name,
'url' => '/shop/catalog/root?id='.$root->id,
'items' => self::getTree($root->children()->all()),
];
}
return $tree;
}