book->chapters; $items = []; foreach ($chapters as $chapter) { $item = []; $item['label'] = $chapter->chapter_name; $item['url'] = ['update-chapter', 'id' => $chapter->id]; $item['active'] = (request('id') == $chapter->id && Yii::$app->controller->action->id == 'update-chapter') || (request('chapter_id') == $chapter->id && Yii::$app->controller->action->id == 'create-chapter'); $item['id'] = $chapter->id; $item['pid'] = $chapter->pid; $item['linkOptions'] = ['data-id' => $chapter->id, 'data-pid' => $chapter->pid]; $items[] = $item; } $menuItems = Tree::build($items, 'id', 'pid', 'items'); ?>