2014-02-21 4 views
1

나는 index.php이며 그 안에 표시해야하는 페이지 템플릿을 생성하려고합니다. index.php이면 home.php 템플릿이 표시됩니다. 당신이 의 index.php? 장 = 장 이름에 경우isset _GET chapter 또는 마커

당신은 chapter.php 템플릿을 참조하십시오. index.php? marker = 마커 이름에있는 경우 marker.php 템플릿이 표시됩니다.

<?php 
    if(!isset($_GET["chapter"])){ 
     $page = "root"; 
     include_once('view/home.php'); 
    } else { 
     $page = $_GET["chapter"]; 
     switch($page){ 
      case "chapter-name": 
      include_once('view/chapter.php'); 
      break; 

      case "marker-name": 
      include_once('view/marker.php'); 
      break; 
     } 
    } 
?> 

감사 :

나는 이제 다음있다!

+5

기존 코드에 문제가 있습니까? 귀하의 질문은 무엇인가? – Roopendra

+0

여기에 대한 답변이나 질문은 무엇입니까? –

답변

0
//Array of configuration views 
$config_template = array(
    'default' => 'view/home.php' , 
    'chapter-name' => 'view/chapter.php' , 
    'marker-name' => 'view/marker.php' , 
) ; 
//Logic to call template 
$include = $config_template['default'] ; 
if (isset($_GET['chapter']) && array_key_exists(strtolower($_GET['chapter']) , $config_template)) { 
    $include = $config_template[$_GET['chapter']] ; 
} 
else if (isset($_GET['marker']) && array_key_exists(strtolower($_GET['marker']) , $config_template)) { 
    $include = $config_template[$_GET['marker']] ; 
} 
//include template 
include_once($include) ; 

이런 식으로 뭔가를 원한다고 생각 자라서 ...

0

어쩌면 당신은 이것을 좋아할 것입니까? 이 $_GET["marker"]

0

에 있기 때문에 $_GET["chapter"]

<?php 
if(isset($_GET["chapter"])) { 
    $page = $_GET["chapter"]; 
    include_once('view/chapter.php'); 
} else if(isset($_GET["marker"])) { 
    $page = $_GET["marker"]; 
    include_once('view/marker.php'); 
} else { 
    $page = "root"; 
    include_once('view/home.php'); 
} 
?> 

당신이 '마커 이름을'얻을하지 않습니다 난 코드가 준비가되어이

<?php 
    if(isset($_GET["chapter"]) && $_GET["chapter"]=='chapter-name') 
    { 
     $page = $_GET["chapter"]; 
     include_once('view/chapter.php'); 
    } 
    else if(isset($_GET["marker"]) && $_GET["marker"]=='marker-name') 
    { 
     $page = $_GET["marker"]; 
     include_once('view/marker.php'); 
    } 
    else 
    { 
     $page = "root"; 
     include_once('view/home.php'); 
    } 
?> 
+0

고마워,이게 내가 원하는거야. –