我是您的助手,下面是您需要翻译的内容:
在过去的几周中,我正在编写一个PHP网站,一直有一个问题困扰着我。在我的index.php文件上,我将所有的模板文件路由到如下位置:
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';
}
但对我来说,这看起来不太干净。有没有更好的处理类似工作的可能性?
我已经尝试过这样做,但对我来说并没有起作用。
$i = 0 ;
switch($i){
case(isset($_GET['search'])):
include_once 'template/template.search.php';
break;
default:
include_once 'template/template.index.php';
break;
}
编辑:标题中的更好的写作可能会误导一些人,所以我肯定在寻找最佳性能。
注:本文主要讨论IT技术相关内容。
switch
语句可以解决这个问题。 - Ryanswitch
。http://ca2.php.net/manual/zh/control-structures.switch.php - dnagirl