getAllSubordinateIds($allCategories, $menu['id']); $menu['isActive'] = 0; if ($categoryId == $menu['id'] || in_array($categoryId, $menu['all_subordinate_ids'])) { $menu['isActive'] = 1; } } var_dump($menutwo); $data = [ 'categoryId' => $categoryId, 'menus' => $menus, 'extraBase' => $configExtraBase, 'menutwo' => $menutwo?'headertwo':"" ]; return View::assign($data)->fetch('public/menu'); } public function index($categoryId = 0,$menutwo = false) { // $menus = Category::getListForFrontMenu(); // $allCategories = Category::getList(false); // foreach ($menus as &$menu) { // $menu['children_ids'] = []; // $menusGroup = []; // if (isset($menu['children'])) { // $menu['children_ids'] = array_column($menu['children'], 'id'); // foreach ($menu['children'] as $child) { // $menusGroup[$child['group_name']][] = $child; // } // } // // $menu['menus_group'] = $menusGroup; // $menu['all_subordinate_ids'] = $this->getAllSubordinateIds($allCategories, $menu['id']); // $menu['isActive'] = 0; // if ($categoryId == $menu['id'] || in_array($categoryId, $menu['all_subordinate_ids'])) { // $menu['isActive'] = 1; // } // } // // $data = [ // 'categoryId' => $categoryId, // 'menus' => $menus, // ]; $data = [ 'menutwo' => $menutwo?'headertwo':"" ]; return View::assign($data)->fetch('public/menu'); } // 所有下级栏目ID private function getAllSubordinateIds($items, $curId = 0) { $list = []; foreach ($items as $k => $item) { if ($item['parent_id'] == $curId) { $list[] = $item['id']; unset($items[$k]); $childrenIds = $this->getAllSubordinateIds($items, $item['id']); if ($childrenIds) { $list = array_merge($list, $childrenIds); } } } return $list; } public function simple() { $data = [ 'extraBase' => ConfigSetting::getConfigContentsByName('extraBase') ]; return View::assign($data)->fetch('public/menu_simple'); } }