改进Think\Route类 支持url映射定义

This commit is contained in:
thinkphp
2013-03-25 16:53:53 +08:00
parent a28899656b
commit f426a438cf
2 changed files with 72 additions and 65 deletions

View File

@@ -179,7 +179,8 @@ class App {
}
}
}
// 监听path_info
Tag::listen('path_info');
// 分析PATHINFO信息
if(empty($_SERVER['PATH_INFO']) && $_SERVER['SCRIPT_NAME'] != $_SERVER['PHP_SELF']) {
$types = explode(',',$config['pathinfo_fetch']);
@@ -195,19 +196,18 @@ class App {
}
}
// 定位模块
if(!empty($_SERVER['PATH_INFO'])) {
// 监听path_info
Tag::listen('path_info');
$part = pathinfo($_SERVER['PATH_INFO']);
define('__EXT__', isset($part['extension'])?strtolower($part['extension']):'');
$_SERVER['PATH_INFO'] = preg_replace('/\.('.trim($config['url_html_suffix'],'.').')$/i', '',$_SERVER['PATH_INFO']);
$paths = explode($config['pathinfo_depr'],trim($_SERVER['PATH_INFO'],'/'));
$part = pathinfo($_SERVER['PATH_INFO']);
define('__EXT__', isset($part['extension'])?strtolower($part['extension']):'');
$_SERVER['PATH_INFO'] = preg_replace('/\.('.trim($config['url_html_suffix'],'.').')$/i', '',$_SERVER['PATH_INFO']);
$url = trim($_SERVER['PATH_INFO'],'/');
if($url) {
$paths = explode($config['pathinfo_depr'],$url);
if($config['require_module'] && !isset($_GET[$var_m])) {
$_GET[$var_m] = array_shift($paths);
$_SERVER['PATH_INFO'] = implode('/',$paths);
}
}elseif(isset($_GET[$var_m]) && !$config['require_module']) {
unset($_GET[$var_m]);
}
// 获取模块名称
define('MODULE_NAME',strtolower(isset($_GET[$var_m])?$_GET[$var_m]:$config['default_module']));
@@ -242,27 +242,8 @@ class App {
}else{
_404('module not exists :'.MODULE_NAME);
}
if(!empty($_SERVER['PATH_INFO'])) {
Tag::listen('path_info');
$url = trim(substr_replace($_SERVER['PATH_INFO'],'',0,strlen($_GET[$var_m])+1),'/');
// 模块路由检测
if(!$config['url_route'] || !Route::check($url)){
$paths = explode($config['pathinfo_depr'],$url);
if($config['require_controller'] && !isset($_GET[$var_c])) {
$_GET[$var_c] = array_shift($paths);
}
if(!isset($_GET[$var_a])) {
$_GET[$var_a] = array_shift($paths);
}
// 解析剩余的URL参数
$var = [];
preg_replace('@(\w+)\/([^\/]+)@e', '$var[\'\\1\']=strip_tags(\'\\2\');', implode('/',$paths));
$_GET = array_merge($var,$_GET);
}
}elseif(isset($_GET[$var_c]) && !$config['require_controller']) {
unset($_GET[$var_c]);
}
// 路由检测
Route::check(trim($_SERVER['PATH_INFO'],'/'));
// 获取控制器名
define('CONTROLLER_NAME', strtolower(isset($_GET[$var_c])?$_GET[$var_c]:$config['default_controller']));