chapters; $items = []; foreach ($chapters as $chapter) { $item = []; $item['label'] = $chapter->chapter_name; $item['url'] = empty($chapter->chapter_body) ? '#' : ['chapter', 'id' => $chapter->id]; $item['active'] = request('id') == $chapter->id && Yii::$app->controller->action->id == 'chapter'; $item['id'] = $chapter->id; $item['pid'] = $chapter->pid; $items[] = $item; } $menuItems = Tree::build($items, 'id', 'pid', 'items'); ?>