mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
路由优化 支持[模块/控制器/操作/参数1/值1/参数2/值2...]路由模式
This commit is contained in:
@@ -266,25 +266,27 @@ class App
|
|||||||
// URL后缀
|
// URL后缀
|
||||||
define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION)));
|
define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION)));
|
||||||
$_SERVER['PATH_INFO'] = __INFO__;
|
$_SERVER['PATH_INFO'] = __INFO__;
|
||||||
if (__INFO__ && !defined('BIND_MODULE')) {
|
if (__INFO__) {
|
||||||
if ($config['url_deny_suffix'] && preg_match('/\.(' . $config['url_deny_suffix'] . ')$/i', __INFO__)) {
|
if ($config['url_deny_suffix'] && preg_match('/\.(' . $config['url_deny_suffix'] . ')$/i', __INFO__)) {
|
||||||
throw new Exception('URL_SUFFIX_DENY');
|
throw new Exception('URL_SUFFIX_DENY');
|
||||||
}
|
}
|
||||||
|
// 还原劫持后真实pathinfo
|
||||||
|
$path_info = (defined('BIND_MODULE')?BIND_MODULE.'/':'') . (defined('BIND_CONTROLLER')?BIND_CONTROLLER.'/':'') . (defined('BIND_ACTION')?BIND_ACTION.'/':'') . __INFO__;
|
||||||
// 路由检测
|
// 路由检测
|
||||||
if (!empty($config['url_route_on'])) {
|
if (!empty($config['url_route_on'])) {
|
||||||
// 开启路由 则检测路由配置
|
// 开启路由 则检测路由配置
|
||||||
Route::register($config['route']);
|
Route::register($config['route']);
|
||||||
$result = Route::check(__INFO__, $config['pathinfo_depr']);
|
$result = Route::check($path_info, $config['pathinfo_depr']);
|
||||||
if (false === $result) {
|
if (false === $result) {
|
||||||
// 路由无效
|
// 路由无效
|
||||||
if ($config['url_route_must']) {
|
if ($config['url_route_must']) {
|
||||||
throw new Exception('route not define ');
|
throw new Exception('route not define ');
|
||||||
} else {
|
} else {
|
||||||
$result = Route::parseUrl(__INFO__);
|
$result = Route::parseUrl($path_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$result = Route::parseUrl(__INFO__);
|
$result = Route::parseUrl($path_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 去除URL后缀
|
// 去除URL后缀
|
||||||
|
|||||||
@@ -435,20 +435,27 @@ class Route
|
|||||||
if (false !== strpos($url, '?')) {
|
if (false !== strpos($url, '?')) {
|
||||||
// [控制器/操作?]参数1=值1&参数2=值2...
|
// [控制器/操作?]参数1=值1&参数2=值2...
|
||||||
$info = parse_url($url);
|
$info = parse_url($url);
|
||||||
$path = explode('/', $info['path']);
|
$path = explode('/', $info['path'], 4);
|
||||||
parse_str($info['query'], $var);
|
parse_str($info['query'], $var);
|
||||||
} elseif (strpos($url, '/')) {
|
} elseif (strpos($url, '/')) {
|
||||||
// [控制器/操作]
|
// [控制器/操作]
|
||||||
$path = explode('/', $url);
|
$path = explode('/', $url, 4);
|
||||||
} else {
|
} else {
|
||||||
// 参数1=值1&参数2=值2...
|
// 参数1=值1&参数2=值2...
|
||||||
parse_str($url, $var);
|
parse_str($url, $var);
|
||||||
}
|
}
|
||||||
if (isset($path)) {
|
if (isset($path)) {
|
||||||
|
$param = [];
|
||||||
|
if(!empty($path[3])) $param = explode('/', array_pop($path));
|
||||||
|
// 解析[模块/控制器/操作]
|
||||||
$action = array_pop($path);
|
$action = array_pop($path);
|
||||||
$action = '[rest]' == $action ? REQUEST_METHOD : $action;
|
$action = '[rest]' == $action ? REQUEST_METHOD : $action;
|
||||||
$controller = !empty($path) ? array_pop($path) : null;
|
$controller = !empty($path) ? array_pop($path) : null;
|
||||||
$module = !empty($path) ? array_pop($path) : null;
|
$module = !empty($path) ? array_pop($path) : null;
|
||||||
|
// 解析path额外的参数
|
||||||
|
for ($i=0; $i<count($param);$i++) {
|
||||||
|
$var[$param[$i]] = $param[++$i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ['route' => [$module, $controller, $action], 'var' => $var];
|
return ['route' => [$module, $controller, $action], 'var' => $var];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user