文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>PHP整合你的站点入口

PHP整合你的站点入口

时间:2008-05-17  来源:剑心通明


大家也许经常在网上看到这样的路径(http://www.aaa.com/aaa/bbb/aaa?id=5),让人不解,这样的网站的实现方式有几种可能性:
1、隐藏文件的扩展名,对这种做法的好处,众说纷纭,不过个人觉得没有必要;
2、用了网站的重定向规则,实现虚拟路径;
3、强制文件解析的方式,实现虚拟路径。
用第2\3种
[url=javascript:;]方法[/url]
可以实现网站的统一接口,合理的整合网站,更好的体现网站的安全性和架构,用这两种方式的网站大多是使用"MVC"模式构建和实现的。
下面是一个例子
访问路径如下:
....../test/*******/Bad
....../test/*******/Good
(其中的"******"可以用任何字符串替换,"......."是你的web路径)
文件的目录结构如下
|--.htaccess
|-- test
|-- Application.php
|-- Controler/GoodControler.php
|-- Controler/BadControler.php
注意文件".htaccess",在windows下不能直接建立的,可以在命令行模式下建立.
文件0 (.htaccess) (这个文件是更改
[url=javascript:;]apache[/url]
的配置方式用的)
forcetype application/x-httpd-php
文件1 (test.php)
parse();
$aa->go();
?>
文件2 (GoodControler.php)
文件3 (BadControler.php)
文件4 (Application.php)
_parsePath();
$this->_getControlerFile();
$this->_getControlerClassname();
}
/*
* 解析当前的访问路径,得到要进行动作
*/
function _parsePath(){
list($path, $param) = explode("?", $_SERVER["REQUEST_URI"]);
$pos = strrpos($path, "/");
$this->action = substr($path, $pos+1);
}
/*
* 通过动作$action,解析得到该$action要用到的controler文件的路径
*/
function _getControlerFile(){
$this->controlerFile = "./Controler/".$this->action."Controler.php";
if(!file_exists($this->controlerFile))
die("Controler文件名(".$this->controlerFile.")解析错误");
require_once $this->controlerFile;
}
/*
* 通过动作$action,解析得到该$action要用到的controler类名
*/
function _getControlerClassname(){
$this->controlerClass = $this->action."Controler";
if(!class_exists($this->controlerClass))
die("Controler类名(".$this->controlerClass.")解析错误");
}
/*
* 调用controler,执行controler的动作
*/
function go(){
$c = new $this->controlerClass();
$c->control();
}
}
?>


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载