I have an index.php and in it I want to generate the page template it should show. So when you're on index.php you see the home.php template.
If you're on the index.php?chapter=chapter-name you see the chapter.php template. And if you're on the index.php?marker=marker-name you see the marker.php template.
I now have the following:
<?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;
}
}
?>
Thanks!
//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) ;
This way the code is ready to grow up...
Maybe you want something like this ?
<?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');
}
?>
With $_GET["chapter"]
you will never get 'marker-name' because it is in $_GET["marker"]
i think you want something like this
<?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');
}
?>