From dfa5143dad9123e04ecf7bf5b7bd9cefe504fc9c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 1 Jun 2016 14:13:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0url=5Fparam=5Ftype=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8F=82=E6=95=B0=20=E7=94=A8=E4=BA=8E=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=93=8D=E4=BD=9C=E6=96=B9=E6=B3=95=E7=9A=84=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=BB=91=E5=AE=9A=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 4 ++-- helper.php | 4 ++-- library/think/App.php | 2 +- library/think/Route.php | 18 ++++++++++++------ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/convention.php b/convention.php index c86e1ea5..37a316a7 100644 --- a/convention.php +++ b/convention.php @@ -63,14 +63,14 @@ return [ 'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'], // pathinfo分隔符 'pathinfo_depr' => '/', - // 获取当前页面地址的系统变量 默认为REQUEST_URI - 'url_request_uri' => 'REQUEST_URI', // URL伪静态后缀 'url_html_suffix' => 'html', // URL普通方式参数 用于自动生成 'url_common_param' => false, //url禁止访问的后缀 'url_deny_suffix' => 'ico|png|gif|jpg', + // URL参数方式 0 按名称成对解析 1 按顺序解析 + 'url_param_type' => 0, // 是否开启路由 'url_route_on' => true, // 是否强制使用路由 diff --git a/helper.php b/helper.php index d796aa48..ee301b07 100644 --- a/helper.php +++ b/helper.php @@ -337,7 +337,7 @@ function trace($log = '[think]', $level = 'log') /** * 获取当前Request对象实例 - * @return \think\Request + * @return Request */ function request() { @@ -349,7 +349,7 @@ function request() * @param mixed $data 输出数据 * @param string $type 输出类型 * @param array $options 参数 - * @return \think\Response + * @return Response */ function response($data = [], $type = '', $options = []) { diff --git a/library/think/App.php b/library/think/App.php index c3f71ecb..9b0f613a 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -389,7 +389,7 @@ class App } if (false === $result) { // 路由无效 解析模块/控制器/操作/参数... 支持控制器自动搜索 - $result = Route::parseUrl($path, $depr, $config['controller_auto_search']); + $result = Route::parseUrl($path, $depr, $config['controller_auto_search'], $config['url_param_type']); } //保证$_REQUEST正常取值 $_REQUEST = array_merge($_POST, $_GET, $_COOKIE); diff --git a/library/think/Route.php b/library/think/Route.php index a4fd5c76..804b7ead 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -827,9 +827,10 @@ class Route * @param string $url URL地址 * @param string $depr URL分隔符 * @param bool $autoSearch 是否自动深度搜索控制器 + * @param integer $paramType URL参数解析方式 0 名称解析 1 顺序解析 * @return array */ - public static function parseUrl($url, $depr = '/', $autoSearch = false) + public static function parseUrl($url, $depr = '/', $autoSearch = false, $paramType = 0) { if (isset(self::$bind['module'])) { // 如果有模块/控制器绑定 @@ -840,7 +841,7 @@ class Route $url = str_replace($depr, '/', $url); } - $result = self::parseRoute($url, $autoSearch, true); + $result = self::parseRoute($url, $autoSearch, true, $paramType); if (!empty($result['var'])) { $_GET = array_merge($result['var'], $_GET); @@ -854,9 +855,10 @@ class Route * @param string $url URL地址 * @param bool $autoSearch 是否自动深度搜索控制器 * @param bool $reverse 是否反转解析URL + * @param integer $paramType URL参数解析方式 0 名称解析 1 顺序解析 * @return array */ - private static function parseRoute($url, $autoSearch = false, $reverse = false) + private static function parseRoute($url, $autoSearch = false, $reverse = false, $paramType = 0) { $url = trim($url, '/'); $var = []; @@ -901,9 +903,13 @@ class Route $action = !empty($path) ? array_shift($path) : null; // 解析额外参数 if (!empty($path)) { - preg_replace_callback('/([^\/]+)\/([^\/]+)/', function ($match) use (&$var) { - $var[strtolower($match[1])] = strip_tags($match[2]); - }, implode('/', $path)); + if ($paramType) { + $var += $path; + } else { + preg_replace_callback('/([^\/]+)\/([^\/]+)/', function ($match) use (&$var) { + $var[strtolower($match[1])] = strip_tags($match[2]); + }, implode('/', $path)); + } } } else { $action = array_pop($path);