From 48e5578611d2c81a04cdf921e74f01354d7660dd Mon Sep 17 00:00:00 2001 From: taekyoungc Date: Tue, 14 Apr 2026 00:33:24 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9A=B4=EC=98=81=20=EB=A9=94=EB=89=B4?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=A7=80=EC=A0=95=ED=8C=90=EB=A7=A4?= =?UTF-8?q?=EC=86=8C=20=ED=99=9C=EC=84=B1=20=EC=83=81=ED=83=9C=EA=B0=80=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=B4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 상단 메뉴 활성 판정을 최장 경로 1건 우선으로 통일해 조회 화면에서 관리 메뉴가 함께 활성화되는 문제를 막았습니다. --- app/Views/admin/layout.php | 38 +++++++++++++++++++++++------------ app/Views/bag/layout/main.php | 37 +++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/app/Views/admin/layout.php b/app/Views/admin/layout.php index 1fc8265..3494f30 100644 --- a/app/Views/admin/layout.php +++ b/app/Views/admin/layout.php @@ -16,11 +16,28 @@ $userNav = session_user_nav_display(); $currentPath = current_nav_request_path(); $adminNavTree = get_admin_nav_tree(); -/** DB 링크(mm_link)만 사용. 짧게 적은 항목(menus 등)은 실제 URI(admin/menus)와 맞춰 후보 비교 */ -$adminNavItemIsCurrent = static function (?string $mmLink) use ($currentPath): bool { - return menu_link_matches_request($mmLink, $currentPath, []); +$resolveAdminNavNodeMatchLen = static function (object $node) use ($currentPath): int { + $maxLen = -1; + foreach (menu_link_candidate_paths($node->mm_link ?? null, $currentPath) as $cand) { + if (menu_single_path_matches_request($cand, $currentPath, [])) { + $maxLen = max($maxLen, strlen($cand)); + } + } + return $maxLen; }; +$activeAdminTopNav = null; +$activeAdminTopLen = -1; +$activeAdminTopNum = PHP_INT_MAX; +foreach ($adminNavTree as $topNode) { + $nodeLen = $resolveAdminNavNodeMatchLen($topNode); + if ($nodeLen > $activeAdminTopLen || ($nodeLen === $activeAdminTopLen && (int) ($topNode->mm_num ?? 0) < $activeAdminTopNum)) { + $activeAdminTopNav = $topNode; + $activeAdminTopLen = $nodeLen; + $activeAdminTopNum = (int) ($topNode->mm_num ?? 0); + } +} + /** 메뉴가 DB에서 안 쓰일 때만(폴백 상단바) 세그먼트 기반 활성 */ $isActive = static function (string $path) use ($uri, $seg3) { if ($path === 'admin' || $path === '') return $uri === ''; @@ -93,15 +110,7 @@ body { overflow: hidden; } children); $parentLink = menu_link_preferred_href_path($navItem->mm_link ?? null, $currentPath); - $parentIsCurrent = $adminNavItemIsCurrent($navItem->mm_link ?? null); - if (! $parentIsCurrent && $hasChildren) { - foreach ($navItem->children as $ch) { - if ($adminNavItemIsCurrent($ch->mm_link ?? null)) { - $parentIsCurrent = true; - break; - } - } - } + $parentIsCurrent = ($activeAdminTopNav !== null && $navItem === $activeAdminTopNav); ?>