mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
修正路由类
This commit is contained in:
@@ -91,20 +91,18 @@ class Error
|
||||
*
|
||||
* @param mixed $error 错误
|
||||
* @param int $code
|
||||
*
|
||||
* @internal param int $errno 错误代码
|
||||
*/
|
||||
public static function halt($error, $code = 1)
|
||||
{
|
||||
$message = is_array($error) ? $error['message'] : $error;
|
||||
$code = is_array($error) ? $error['code'] : $code;
|
||||
|
||||
$e = ['mssage' => $message, 'code' => $code];
|
||||
if (APP_DEBUG) {
|
||||
//调试模式下输出错误信息
|
||||
if (!is_array($error)) {
|
||||
$trace = debug_backtrace();
|
||||
$e['message'] = $error;
|
||||
$e['code'] = $code;
|
||||
$e['file'] = $trace[0]['file'];
|
||||
$e['line'] = $trace[0]['line'];
|
||||
ob_start();
|
||||
@@ -119,8 +117,11 @@ class Error
|
||||
if (!empty($error_page)) {
|
||||
header('Location: ' . $error_page);
|
||||
} else {
|
||||
$e['code'] = $code;
|
||||
$e['message'] = Config::get('show_error_msg') ? $message : Config::get('error_message');
|
||||
}
|
||||
} else {
|
||||
$e = ['mssage' => $message, 'code' => $code];
|
||||
}
|
||||
|
||||
$type = Config::get('default_return_type');
|
||||
|
||||
@@ -530,12 +530,12 @@ class Route
|
||||
// 外部地址中可以用动态变量 采用 :1 :2 的方式
|
||||
// 'news/:month/:day/:id'=>['News/read?cate=1','status=1'],
|
||||
// 'new/:id'=>['/new.php?id=:1',301], 重定向
|
||||
private static function parseRule($rule, $route, $url)
|
||||
private static function parseRule($rule, $route, $pathinfo)
|
||||
{
|
||||
// 获取URL地址中的参数
|
||||
$paths = explode('/', $pathinfo);
|
||||
// 获取路由地址规则
|
||||
$url = is_array($route) ? $route[0] : $route;
|
||||
// 获取URL地址中的参数
|
||||
$paths = explode('/', $url);
|
||||
// 解析路由规则
|
||||
$matches = [];
|
||||
$rule = explode('/', $rule);
|
||||
@@ -589,6 +589,10 @@ class Route
|
||||
}
|
||||
}
|
||||
$var = array_merge($matches, $var);
|
||||
// 解析剩余的URL参数
|
||||
if (!empty($paths)) {
|
||||
preg_replace_callback('/(\w+)\/([^\/]+)/', function ($match) use (&$var) {$var[strtolower($match[1])] = strip_tags($match[2]);}, implode('/', $paths));
|
||||
}
|
||||
// 解析路由自动传人参数
|
||||
if (is_array($route) && isset($route[1])) {
|
||||
parse_str($route[1], $params);
|
||||
@@ -607,7 +611,7 @@ class Route
|
||||
// 参数值和外部地址中可以用动态变量 采用 :1 :2 的方式
|
||||
// '/new\/(\d+)\/(\d+)/'=>['News/read?id=:1&page=:2&cate=1','status=1'],
|
||||
// '/new\/(\d+)/'=>['/new.php?id=:1&page=:2&status=1','301'], 重定向
|
||||
private static function parseRegex($matches, $route, $url)
|
||||
private static function parseRegex($matches, $route, $pathinfo)
|
||||
{
|
||||
// 获取路由地址规则
|
||||
$url = is_array($route) ? $route[0] : $route;
|
||||
@@ -620,6 +624,13 @@ class Route
|
||||
// 解析路由地址
|
||||
$result = self::parseRoute($url);
|
||||
$var = $result['var'];
|
||||
// 解析剩余的URL参数
|
||||
$regx = substr_replace($pathinfo, '', 0, strlen($matches[0]));
|
||||
if ($regx) {
|
||||
preg_replace_callback('/(\w+)\/([^\/]+)/', function ($match) use (&$var) {
|
||||
$var[strtolower($match[1])] = strip_tags($match[2]);
|
||||
}, $regx);
|
||||
}
|
||||
// 解析路由自动传人参数
|
||||
if (is_array($route) && isset($route[1])) {
|
||||
parse_str($route[1], $params);
|
||||
|
||||
Reference in New Issue
Block a user