I was writing a Site in php the last few weeks and always had a question in my mind. On my index.php I route all the templates file like this
if(isset($_GET['search'])){
include_once 'template/template.search.php';
}
elseif(isset($_GET['newsletter'])){
include_once 'template/template.newsletter.php';
}
elseif(isset($_GET['product'])){
include_once 'template/template.product.php';
}
elseif(isset($_GET['categories'])){
include_once 'template/template.categorie.php';
}
elseif(isset($_GET['about'])){
include_once 'template/template.about.php';
}
elseif(isset($_GET['sitemap'])){
include_once 'template/template.sitemap.php';
}
else
{
include_once 'template/template.index.php';
}
But for me it dosen't look very clean. Is there a better possibility to handle a job like this ?
I already tried it like this, but didn't worked out for me
$i = 0 ;
switch($i){
case(isset($_GET['search'])):
include_once 'template/template.search.php';
break;
default:
include_once 'template/template.index.php';
break;
}
Edit: Better writing in the title was a bit misleading some of you, so I'm searching for the best performance for sure.
switchstatement would solve thisswitchca2.php.net/manual/en/control-structures.switch.php