最近想用php做一个网站,想要用单入口进行实现,但是对这个不了解,通过度娘查询有了大概的了解。首页index.php部分内容如下:$action = @$_GET['action'] == "" ? "welcome" : $_GET['action'];$dir = str_replace('\\', '/', dirname(__FILE__)); //当前文件所在的目录
//echo "<BR>path:".$dir.'/controller/'.$action.".php";
require_once $dir.'/controller/'.$action.".php";
$newPdo = new $action();
controller/welcome.php内容部分:<?php if(!defined('POWER')){ exit("Access Denied!"); }
class Welcome {
function __construct() {
$this->view();
}//end func contruction
function view() {
require_once 'view/welcome.php';
}//end func view
}//end class welcome ?>
view/welcome.php内容:<?php if(!defined('POWER')){ exit("Access Denied!"); } ?>
<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>单点登录网站首页</title>
</head>
<body>
这是单点登录网站首页
<div>
<a href="index.php?action=login&func=view">登录</a><br/>
<a href="index.php?action=friend&func=view">朋友</a><br/>
</div>
</body>
</html>
首页面如下图:
http://localhost/singleEnter/
点击登录按钮,登录页面如下图:
http://localhost/singleEnter/index.php?action=login&func=view
再次点击登录,如下图:
http://localhost/singleEnter/index.php/controller/login.php
继续点击登录,如下图:
http://localhost/singleEnter/index.php/controller/index.php?action=login&func=view
很奇怪地址的变化,为什么会一直增长?请教大神们
//echo "<BR>path:".$dir.'/controller/'.$action.".php";
require_once $dir.'/controller/'.$action.".php";
$newPdo = new $action();
controller/welcome.php内容部分:<?php if(!defined('POWER')){ exit("Access Denied!"); }
class Welcome {
function __construct() {
$this->view();
}//end func contruction
function view() {
require_once 'view/welcome.php';
}//end func view
}//end class welcome ?>
view/welcome.php内容:<?php if(!defined('POWER')){ exit("Access Denied!"); } ?>
<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>单点登录网站首页</title>
</head>
<body>
这是单点登录网站首页
<div>
<a href="index.php?action=login&func=view">登录</a><br/>
<a href="index.php?action=friend&func=view">朋友</a><br/>
</div>
</body>
</html>
首页面如下图:
http://localhost/singleEnter/
点击登录按钮,登录页面如下图:
http://localhost/singleEnter/index.php?action=login&func=view
再次点击登录,如下图:
http://localhost/singleEnter/index.php/controller/login.php
继续点击登录,如下图:
http://localhost/singleEnter/index.php/controller/index.php?action=login&func=view
很奇怪地址的变化,为什么会一直增长?请教大神们
是的
像yii的protected目录用户不能直接访问(htaccess),外面有个index.php解析url后调用对应的文件.
当然了,对url和目录结构都要约定好.比如PSR-0之类
一般url结构 index/controler/method/parameters/value