pathinfo URL规则修改还原

This commit is contained in:
thinkphp
2013-03-14 14:42:55 +08:00
parent 90fac61dea
commit dec45af1aa
2 changed files with 13 additions and 33 deletions

View File

@@ -104,12 +104,12 @@ class App {
Tag::listen('action_end',$call); Tag::listen('action_end',$call);
}else{ }else{
// 操作方法不是Public 抛出异常 // 操作方法不是Public 抛出异常
throw new ReflectionException(); throw new \ReflectionException();
} }
} catch (ReflectionException $e) { } catch (\ReflectionException $e) {
// 操作不存在 // 操作不存在
if(method_exists($instance,'_empty')) { if(method_exists($instance,'_empty')) {
$method = new ReflectionMethod($instance,'_empty'); $method = new \ReflectionMethod($instance,'_empty');
$method->invokeArgs($instance,array($action,'')); $method->invokeArgs($instance,array($action,''));
}else{ }else{
_404('action not exists :'.ACTION_NAME); _404('action not exists :'.ACTION_NAME);
@@ -220,12 +220,10 @@ class App {
if(is_file(MODULE_PATH.'config'.EXT)) { if(is_file(MODULE_PATH.'config'.EXT)) {
$config = Config::set(include MODULE_PATH.'config'.EXT); $config = Config::set(include MODULE_PATH.'config'.EXT);
} }
if(Config::has('app_status')) { if($config['app_status']) {
// 读取应用状态配置文件
$status = Config::get('app_status');
// 加载对应的项目配置文件 // 加载对应的项目配置文件
if(is_file(MODULE_PATH.$status.EXT)) if(is_file(MODULE_PATH.$config['app_status'].EXT))
$config = Config::set(include MODULE_PATH.$status.EXT); $config = Config::set(include MODULE_PATH.$config['app_status'].EXT);
} }
// 加载别名文件 // 加载别名文件
if(is_file(MODULE_PATH.'alias'.EXT)) { if(is_file(MODULE_PATH.'alias'.EXT)) {
@@ -249,29 +247,14 @@ class App {
Tag::listen('path_info'); Tag::listen('path_info');
$url = trim(substr_replace($_SERVER['PATH_INFO'],'',0,strlen($_GET[$var_m])+1),'/'); $url = trim(substr_replace($_SERVER['PATH_INFO'],'',0,strlen($_GET[$var_m])+1),'/');
// 模块路由检测 // 模块路由检测
if(!Route::check($url,$config['url_route_rules'])){ if(!$config['url_route'] || !Route::check($url,$config['url_route_rules'])){
// PATHINFO URL规则 默认为 Controller/Action/ // PATHINFO URL规则 默认为 Controller/Action/
$paths = explode($config['pathinfo_depr'],$url); $paths = explode($config['pathinfo_depr'],$url);
if(Config::get('url_pathinfo_rule')) { if($config['require_controller'] && !isset($_GET[$var_c])) {
// 按照定义的URL规则解析 c/a/id?var1=val1&var2=val2... $_GET[$var_c] = array_shift($paths);
$rules = parse_url(Config::get('url_pathinfo_rule')); }
if(!empty($rules['path'])) { if(!isset($_GET[$var_a])) {
$array = explode('/',$rules['path']); $_GET[$var_a] = array_shift($paths);
foreach($array as $val){
$_GET[$val] = array_shift($paths);
}
}
if(!empty($rules['query'])) {
parse_str($rules['query'],$params);
$_GET = array_merge($_GET,$params);
}
}else{
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参数 // 解析剩余的URL参数
$var = []; $var = [];
@@ -281,7 +264,7 @@ class App {
}elseif(isset($_GET[$var_c]) && !$config['require_controller']) { }elseif(isset($_GET[$var_c]) && !$config['require_controller']) {
unset($_GET[$var_c]); unset($_GET[$var_c]);
} }
dump($_GET);
// 获取控制器名 // 获取控制器名
define('CONTROLLER_NAME', strtolower(isset($_GET[$var_c])?$_GET[$var_c]:$config['default_controller'])); define('CONTROLLER_NAME', strtolower(isset($_GET[$var_c])?$_GET[$var_c]:$config['default_controller']));

View File

@@ -15,9 +15,6 @@ class Route {
static public function check($regx,$rules) { static public function check($regx,$rules) {
// 优先检测是否存在PATH_INFO // 优先检测是否存在PATH_INFO
if(empty($regx)) return true; if(empty($regx)) return true;
if(!Config::get('url_route')) {
return false;
}
// 路由处理 // 路由处理
if(!empty($rules)) { if(!empty($rules)) {
// 分隔符替换 确保路由定义使用统一的分隔符 // 分隔符替换 确保路由定义使用统一的分隔符