출처 : http://www.nzeo.com/bbs/zboard.php?id=p_study&page=1&sn1=&divpage=1&sn=off&ss=on&sc=on&keyword=$id&select_arrange=headnum&desc=asc&no=416

위와같이 수정하신후.. index.php?id=body_frame.php  이라고 불러온다면 ...
$id = body_frame.php 으로 수정되어 출력 됩니다.  매우 편리한 방법으로 개선되었지요..? ^.^

이제 내용이 바뀔때마다 index.php파일을 따로 만들필요 없이 하나의 index.php 파일로 내용만 바뀐페이지가
얼마든지 나올수 있습니다.  이렇게 나고 끝해도 되겠지만.. ^.^  또 한가지 기능을 넣어 봅니다.

index.php
----------------------------------------------------
<Table>
        <tr><td>
                                <? include ("Top_frame.php"); ?>
        </td></tr>

        <tr><td>
                <Table>
                        <tr><td>
                                        <? include ("Left_frame.php"); ?>
                        </td><td>
                                        <? if (is_file("$id")) : include ("$id"); endif; ?>
                        </td></tr>
                </Table>
        </td></tr>
</Table>

어라? 바뀐게 별로 없지요..? ^.^ is_file 명령어만 추가 되었습니다.
if(만약) is_file(파일이 존재하는지?) : 실행 (include); 끝(endif;)
조금더 설명하자면
만약 파일이 존재하면 실행하고 끝 : 약 파일이 없다면 실행안하고 끝
^.^ Top_frame 쪽이나 left_frame 쪽에 달아 두어도 도움이 될것 같습니다.

------------------------------------------------------------

<?
if (is_file("/home/index/body/$id.php")) :
include ("/home/index/body/$id.php");
endif;
?>
                        </td></tr>
                </Table>
        </td></tr>
</Table>

네~ 이제는 디렉토리에 이어서 확장자 까지도 소스에 들어가 있습니다.
불러올때는 단순히 index.php?id=body_frame 이라고 불러오면
예전의  $id=/home/index.body/body_frame.php 과 비교해보면 많이 편리 해졌지요..?


초보의 초보를위한 초보에의한 강의 입니다.


index.php
-----------------------------------------------------------
<Table>
        <tr><td>
                                <? include ("Top_frame.php"); ?>
        </td></tr>

        <tr><td>
                <Table>
                        <tr><td>
                                        <? include ("Left_frame.php"); ?>
                        </td><td>
<? if (is_file("$id")) :
include ("$id");
endif; ?>
                        </td></tr>
                </Table>
        </td></tr>
</Table>





위와 같은 내용에서 나는 index.php 파일과 내용에 들어갈 파일과 따로 떨어 뜨려 놓고 싶다.
하시는분도 계실것입니다. 디렉토리를 따로 따로 분류하여 알아보기 쉽도록 하시는게 나중에 수정하시는데도
많은 도움이 되실것입니다.

home      - index      - body
              - leftmenu
              - image
              - topmenu

위와 같은 형태로 디렉토리가 존재 한다고 생각을 해보지요..

그럼 이번에도 무식하게 index.php?id=/home/index/body/body_frame.php   이와 같은 형태로..
불러와볼까요..? 그럼 나중에도 계속 불러 올때는 /home/index/body/ 라는 디렉토리를 매번 써주어야 합니다.
귀찮죠..? ^.^ 저는 불편한건 딱 질색 입니다. 이번에도 조금 편하게 수정을 해보지요...


index.php
-----------------------------------------------------------
<Table>
        <tr><td>
                                <? include ("Top_frame.php"); ?>
        </td></tr>

        <tr><td>
                <Table>
                        <tr><td>
                                        <? include ("Left_frame.php"); ?>
                        </td><td>
<?
if (is_file("/home/index/body/$id")) :
include ("/home/index/body/$id");
endif;
?>
                        </td></tr>
                </Table>
        </td></tr>
</Table>

위와같이 수정을 하면 어떻게 될까요..?
index.php?id=body_frame.php 이라고 불러오더라도...
자동적으로 /home/index/body/라는 디렉토리에서 불러 오게 됩니다.

아하~ 그렇지요? ^.^ 이제 원하시는 디렉토리에서 불러 오시면 되겠습니다.

디렉토리를 넣는 방법을 알았으니 조금더 응용을 해볼까요..?


index.php
-----------------------------------------------------------
<Table>
        <tr><td>
                                <? include ("Top_frame.php"); ?>
        </td></tr>

        <tr><td>
                <Table>
                        <tr><td>
                                        <? include ("Left_frame.php"); ?>
                        </td><td>
<?
if (is_file("/home/index/body/$id.php")) :
include ("/home/index/body/$id.php");
endif;
?>
                        </td></tr>
                </Table>
        </td></tr>
</Table>

네~ 이제는 디렉토리에 이어서 확장자 까지도 소스에 들어가 있습니다.
불러올때는 단순히 index.php?id=body_frame 이라고 불러오면
예전의  $id=/home/index.body/body_frame.php 과 비교해보면 많이 편리 해졌지요..?

index.php
-----------------------------------------------------------
<Table>
        <tr><td>
                                <? include ("Top_frame.php"); ?>
        </td></tr>

        <tr><td>
                <Table>
                        <tr><td>
<?
if (is_file("/home/index/leftmenu/$id.php")) :
include ("/home/index/leftmenu/$id.php");
endif;
?>

                        </td><td>
<?
if (is_file("/home/index/body/$id.php")) :
include ("/home/index/body/$id.php");
endif;
?>
                        </td></tr>
                </Table>
        </td></tr>
</Table>

위와같이 수정을 하시게 된다면 어떨 결과가 나올까요.?
left_frame 즉 왼쪽 부분의 메뉴부분 역시 /home/index/leftmenu/ 라는 디렉토리에서
?id= 값에 따라 불러 오게 됩니다.

장점은 페이지마다 다른 메뉴를 보여 줄수 있다는 점이 되겠습니다.

이를 조금더 응용해서 Top_frame 부분도 사용을 하게 된다면
각각의 페이지 마다 전체 분위기가 바뀌는 효과를 활용할수 있게 됩니다.

그런데 단점이 하나 있지요..? ㅡ.ㅡ 각각의 페이지 마다 메뉴를 따로 따로 만들려면
에구~ ㅜ.ㅜ 힘들어라.. 메뉴가 수십개 되는 홈페이지라면 수십개의 페이지를 따로..? 헉~~
거기다 더 억울한건 똑같은 메뉴를 사용하고 싶다면 똑같은 내용의 파일을  페이지 마다 만들어야 합니다.

그러기는 싫지요..? ^.^  그렇다면 다음 소스를 ....

index.php
-----------------------------------------------------------
<Table>
        <tr><td>
                                <? include ("Top_frame.php"); ?>
        </td></tr>

        <tr><td>
                <Table>
                        <tr><td>
<?
if (is_file("/home/index/leftmenu/$leftmenu.php")) :
include ("/home/index/leftmenu/$leftmenu.php");
endif;
?>
                        </td><td>
<?
if (is_file("/home/index/body/$id.php")) :
include ("/home/index/body/$id.php");
endif;
?>
                        </td></tr>
                </Table>
        </td></tr>
</Table>

위와같이 수정을 하게 된다면.. 어라 $leftmenu ? 새로운 변수가 나왔네요..
네 그렇습니다. ^.^ leftframe 과 bodyframe이 따로 따로 놀게 된것 입니다.

불러올때는 index.php?id=body_frame&leftmenu=left_frame 이렇게 불러온다면..
leftframe은 left_frame.php 를
bodyframe은 body_frame.php 를 불러오게 됩니다.

좌측메뉴와 내용과는 따로 따로 불러 올수 있게 됩니다.

------------------------------------------------------------------

index.php
-----------------------------------------------------------
<Table>
        <tr><td>
<?
if (is_file("/home/index/topmenu/$menu.php")) {
include ("/home/index/topmenu/$menu.php"); }
else {
include ("/home/index/topmenu/menu.php"); }
?>
        </td></tr>

        <tr><td>
                <Table>
                        <tr><td>
<?
if (is_file("/home/index/leftmenu/$menu.php")) {
include ("/home/index/leftmenu/$menu.php"); }
else {
include ("/home/index/leftmenu/menu.php"); }
?>
                        </td><td>
<?
if (is_file("/home/index/body/$id.php")) :
include ("/home/index/body/$id.php");
endif;
?>
                        </td></tr>
                </Table>
        </td></tr>
</Table>

이렇게 전체적으로 수정을 해주신다면 ^.^
$menu 값에 따라 menu.php라는 상단과 좌측의 기본 홈페이지 모양이 나오게 됩니다.
특별한 페이지 부분에서만 특별한 메뉴를 불러와 전체적인 분위기를 바꿀수 있게되었습니다.

profile