/** * List menu item by menu location; * * @param string $menu_location * @param int $menu_parent * * @return array|null */ protected static function getListMenuItem($menu_location, $menu_parent = 0) { $menuItem = []; $menuItemModel = MenuItem::find()->innerJoinWith(['menu'])->andWhere(['menu_location' => $menu_location])->andWhere(['menu_parent' => $menu_parent])->orderBy('menu_order')->all(); if (empty($menuItemModel)) { return $menuItem = null; } foreach ($menuItemModel as $model) { $menuItem[] = ['id' => $model->id, 'label' => $model->menu_label, 'url' => $model->menu_url, 'parent' => $model->menu_parent, 'items' => self::getListMenuItem($menu_location, $model->id)]; } return $menuItem; }
/** * Finds the Post model based on its primary key value. * If the model is not found, it will return false. * * @param integer $id * * @return MenuItem|bool|null|static */ protected function findMenuItem($id) { if (($model = MenuItem::findOne($id)) !== null) { return $model; } else { return false; } }