- javascript 바코드 생성
- javascript 바코드스캔
- 바코드 스캔하기
- XSS PHP
- asp.net dropdownlist
- asp.net Select
- php 캐쉬제거
- 404에러페이지
- TempData
- javascript redirection
- 말줄임표시
- django 엑셀불러오기
- 맥 오라클설치
- javascript 유효성체크
- ViewData
- ASP.Net Core 404
- 하드 윈도우 복사
- 바코드 생성하기
- jquery 바코드
- ViewBag
- jquery 바코드생성
- SSD 복사
- 파일업로드 체크
- 타임피커
- 하드 마이그레이션
- 강제이동
- asp.net core Select
- 파일업로드 유효성체크
- Mac Oracle
- XSS방어
웹개발자의 기지개
[PHP] 유용한 실무팁5 - 2단계 메뉴에 따른 Url 주소와 매핑하기 본문
실무에서 2단계 메뉴(대분류, 중분류) 를 도메인주소별로 매핑해 보자.
http://도메인/member/member_reg.html
http://도메인/community/notice_list.html
http://도메인/intro/face.html
위에서 예를 든것처럼 폴더와 파일형태로 2단계로 구분되어 있는 디렉토리 구성형태로 설계되어 있다.
[ menu.html ] - 상기 이미지 코딩부분만 별도의 include 소스로 구성한다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
<?
$selfPageArr = explode("/",$_SERVER[PHP_SELF]);
?>
<section id="app">
<div class="container">
<div class='select-menu' >
<a href='/index.html'><i class="icofont-home" ></i></a>
<select id="sbx_class" name="sbx_class" onchange="sub1Chg()">
<option value="">선택하세요</option>
<option value="unite" <?if (preg_match("/".$selfPageArr[1]."/i","unite", $matches)) echo "selected";?>>연합회소개</option>
<option value="business" <?if (preg_match("/".$selfPageArr[1]."/i","business", $matches)) echo "selected";?>>사무처</option>
<option value="job" <?if (preg_match("/".$selfPageArr[1]."/i","job", $matches)) echo "selected";?>>광역취업지원센터</option>
<option value="scc" <?if (preg_match("/".$selfPageArr[1]."/i","scc", $matches)) echo "selected";?>>경로당광역지원센터</option>
<option value="volun" <?if (preg_match("/".$selfPageArr[1]."/i","volun", $matches)) echo "selected";?>>노인자원봉사지원센터</option>
<option value="univ" <?if (preg_match("/".$selfPageArr[1]."/i","univ", $matches)) echo "selected";?>>부설노인대학원</option>
<option value="community" <?if (preg_match("/".$selfPageArr[1]."/i","community", $matches)) echo "selected";?>>커뮤니티</option>
<option value="member" <?if (preg_match("/".$selfPageArr[1]."/i","member", $matches)) echo "selected";?>>회원</option>
</select>
<?
$dirname = $selfPageArr[1]; // unite
$subFilStr = $selfPageArr[2]; // org.html
$subFileName = explode(".",$selfPageArr[2]); // $subFileName[0] = org
if (strpos($subFileName,'_') !== false) { // org_input 일때
$subFileName2Arr = explode("_",$subFileName[0]);
} else {
$subFileName2Arr[0] = $subFileName[0];
}
?>
<select id="sbx_item" name="sbx_item" class="ml5 w200" onchange="sub2Chg()">
<?
switch ($dirname) {
case "unite" :
echo "<option value='greeting'>회장인사말</option>";
echo "<option value='found'>설립현황</option>";
echo "<option value='history'>연혁</option>";
echo "<option value='org'>조직도</option>";
echo "<option value='group'>직원 및 업무</option>";
echo "<option value='officer'>경상북도 임직원현황</option>";
echo "<option value='map'>찾아오시는 길</option>";
break;
case "business" :
echo "<option value='center'>총무국</option>";
echo "<option value='job'>광역취업지원센터</option>";
echo "<option value='scc'>경로당광역지원센터</option>";
echo "<option value='volun'>노인자원봉사지원센터</option>";
echo "<option value='univ'>부설노인대학원</option>";
break;
case "job" :
echo "<option value='intro'>광역취업지원센터소개</option>";
echo "<option value='business'>사업안내</option>";
echo "<option value='history'>연혁</option>";
echo "<option value='org'>조직도</option>";
echo "<option value='news'>주요활동소식</option>";
echo "<option value='recruit'>구인·구직신청</option>";
break;
case "scc" :
echo "<option value='intro'>경로당광역지원센터소개</option>";
echo "<option value='business'>사업안내</option>";
echo "<option value='history'>연혁</option>";
echo "<option value='seniorstatus'>경로당현황</option>";
echo "<option value='news'>주요활동소개</option>";
break;
case "volun" :
echo "<option value='intro'>노인자원봉사지원센터 소개</option>";
echo "<option value='business'>사업안내</option>";
echo "<option value='history'>연혁</option>";
echo "<option value='partic'>조직도</option>";
echo "<option value='benefit'>노인자원봉사단참여</option>";
echo "<option value='news'>주요활동소식</option>";
break;
case "univ" :
echo "<option value='superior'>노인지도자대학</option>";
echo "<option value='edu'>노인대학</option>";
echo "<option value='gallery'>대학원 갤러리</option>";
break;
case "community" :
echo "<option value='notice'>공지사항</option>";
echo "<option value='activities'>활동소식</option>";
echo "<option value='notify'>공고고시</option>";
echo "<option value='news'>보도자료</option>";
echo "<option value='gallery'>연합회갤러리</option>";
echo "<option value='video'>동영상</option>";
echo "<option value='data'>자료실</option>";
echo "<option value='monthschedule'>월간일정</option>";
break;
case "member" :
echo "<option value='login'>로그인</option>";
echo "<option value='join'>회원가입</option>";
break;
}
?>
</select>
<?
// if (preg_match("/".$subFileName[0]."/i",$subFileName[0], $matches)) echo "<script>$(\"#sbx_item\").val(\"$subFileName[0]\").prop(\"selected\", true);</script>";
if (strpos($subFileName[0],$subFileName2Arr[0]) !== false) echo "<script>$(\"#sbx_item\").val(\"$subFileName2Arr[0]\").prop(\"selected\", true);</script>";
?>
</div>
</div>
</section>
<script>
// 첫번째 메뉴 변경시
function sub1Chg() {
var gap = document.getElementById("sbx_class").value;
switch (gap)
{
case "unite" : location.href="/unite/greeting.html";break;
case "business" : location.href="/business/center.html";break;
case "job" : location.href="/job/intro.html";break;
case "scc" : location.href="/scc/intro.html";break;
case "volun" : location.href="/volun/intro.html";break;
case "univ" : location.href="/univ/superior.html";break;
case "community" : location.href="/community/notice.html";break;
case "member" : location.href="/member/login.html";break;
}
}
// 두번째 메뉴 변경시
function sub2Chg() {
var gap1 = document.getElementById("sbx_class").value;
var gap2 = document.getElementById("sbx_item").value;
if (gap1=="unite")
{
switch (gap2)
{
case "greeting" : location.href="/unite/greeting.html";break;
case "found" : location.href="/unite/found.html";break;
case "history" : location.href="/unite/history.html";break;
case "org" : location.href="/unite/org.html";break;
case "group" : location.href="/unite/group.html";break;
case "officer" : location.href="/unite/officer.html";break;
case "map" : location.href="/unite/map.html";break;
}
} else if (gap1=="business")
{
switch (gap2)
{
case "center" : location.href="/business/center.html";break;
case "scc" : location.href="/business/scc.html";break;
case "job" : location.href="/business/job.html";break;
case "volun" : location.href="/business/volun.html";break;
case "univ" : location.href="/business/univ.html";break;
}
} else if (gap1=="job")
{
switch (gap2)
{
case "intro" : location.href="/job/intro.html";break;
case "business" : location.href="/job/business.html";break;
case "history" : location.href="/job/history.html";break;
case "org" : location.href="/job/org.html";break;
case "news" : location.href="/job/news.html";break;
case "recruit" : location.href="/job/recruit.html";break;
}
} else if (gap1=="scc")
{
switch (gap2)
{
case "intro" : location.href="/scc/intro.html";break;
case "business" : location.href="/scc/business.html";break;
case "history" : location.href="/scc/history.html";break;
case "org" : location.href="/scc/org.html";break;
case "seniorstatus" : location.href="/scc/seniorstatus.html";break;
case "news" : location.href="/scc/news.html";break;
}
} else if (gap1=="volun")
{
switch (gap2)
{
case "intro" : location.href="/volun/intro.html";break;
case "business" : location.href="/volun/business.html";break;
case "history" : location.href="/volun/history.html";break;
case "partic" : location.href="/volun/partic.html";break;
case "benefit" : location.href="/volun/benefit.html";break;
case "news" : location.href="/volun/news.html";break;
}
} else if (gap1=="univ")
{
switch (gap2)
{
case "superior" : location.href="/univ/superior.html";break;
case "intro" : location.href="/univ/intro.html";break;
case "edu" : location.href="/univ/edu.html";break;
case "enter" : location.href="/univ/enter.html";break;
case "gallery" : location.href="/univ/gallery.html";break;
case "alumni" : location.href="/univ/alumni.html";break;
}
} else if (gap1=="community")
{
switch (gap2)
{
case "notice" : location.href="/community/notice.html";break;
case "activities" : location.href="/community/activities.html";break;
case "notify" : location.href="/community/notify.html";break;
case "news" : location.href="/community/news.html";break;
case "gallery" : location.href="/community/gallery.html";break;
case "video" : location.href="/community/video.html";break;
case "data" : location.href="/community/data.html";break;
case "monthschedule" : location.href="/community/monthschedule.html";break;
}
} else if (gap1=="member")
{
switch (gap2)
{
case "login" : location.href="/member/login.html";break;
case "join" : location.href="/member/join.html";break;
}
}
}
</script>
|
cs |
전체 소스를 다 올려서 다소 길게 보일수 있는데,
$selfPageArr = explode("/",$_SERVER[PHP_SELF]); 에는 현재페이지의 url 을 읽어와서 '/' 로 자른다음 배열로 리턴값을 받는다.
http://도메인/unite/org.html
$dirname = $selfPageArr[1]; // unite
$subFilStr = $selfPageArr[2]; // org.html
$subFileName = explode(".",$selfPageArr[2]); // $subFileName[0] = org
각각의 구분값을 나누어 정리한다.
sub1Chg() 와 sub2Chg() 형태로 두메뉴를 변경시에 javascript 바로가기 기능 또한 만들어 준다.
if (strpos($subFileName[0],$subFileName2Arr[0]) !== false) echo "<script>$(\"#sbx_item\").val(\"$subFileName2Arr[0]\").prop(\"selected\", true);</script>";
부분은 현재 선택한 메뉴를 Selected 시키는 기능이다.
'PHP' 카테고리의 다른 글
[PHP] 사이트가 죽었는지 확인하기 Curl 이용 (0) | 2023.11.24 |
---|---|
[PHP] 카카오 로그인 ( with 네이버 로그인 ) (0) | 2023.08.10 |
[PHP] 유용한 실무팁4 - 최근 5년간 자동 Select박스 만들기, Timestamp 활용 (0) | 2023.05.16 |
[PHP] 문자열(string) 변수를 정수형(int) 변수로 캐스팅 (0) | 2023.05.16 |
[PHP] 엑셀다운로드 파일을 만들때 휴대폰번호 최초 0번 나오게 (0) | 2023.05.08 |