我注意到,在几个站点中,他们可以只从index.php运行整个站点,我也注意到phpmyadmin在某种程度上也有同样的效果。
一个这样做的网站的例子是Try Open School,它是一个演示网站,你可以使用(admin作为密码,admin作为用户名,或者老师、老师、学生、学生)登录。如果您注意到关于URL
的所有更改都是Query String
。
我浏览了一下网站,我所能看到的只是一页上的大量代码,但我不认为是这样。我试了试,做了这样的事。。
<?php
if($_GET['ref'] == 'home')
{
require_once("home.php");
}
elseif($_GET['ref'] == 'profile')
{
require_once("profile.php");
}
?>
我使用URL Query String
来参考不同的页面并做出其他逻辑决策。
我在页面上做了很多这方面的工作,页面中包含数百个if else statements
。我不知道我是否在做他们在他们网站上做的事情。我喜欢这个概念,并希望在我自己的网站上实现这种东西。
我将感谢所有关于如何进行这项工作的帮助。感谢
如果$_GET['ref']是选择页面的唯一参数。php开关可能是更好的解决方案。
如果你想在索引文件中获得更少的代码行,你可以把开关放在separetephp文件中!
像这样(index.php)
<?php
echo "<div id=header>Someinput</div>
<div id=menu>Some menu input</div>
<div id=site>";
require("switch.php");
echo "</div>
<div id=footer>Some footer input</div>";
?>
然后(switch.php):
<?php
switch($_GET['ref']){
case "page1":
include("page1.php");
break 1;
case "page2":
include("page2.php");
break 1;
default:
include("404.php");
}
?>