From a7df3d52e2ee60f4cea98ddcec8dfa072aa3962c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 16 Jun 2016 13:39:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BRequest=E7=9A=84param?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=92=8CRoute=E7=B1=BB=E7=9A=84parseUrlParam?= =?UTF-8?q?s=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 17 +++++++++++------ library/think/Route.php | 6 ++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 3e1a3940..78d8d0e0 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -173,23 +173,23 @@ class Request $info['path'] = '/'; } $options = []; - $options['param'] = $params; $queryString = ''; if (isset($info['query'])) { parse_str(html_entity_decode($info['query']), $query); - if (!empty($options['param'])) { - $options['param'] = array_replace($query, $options['param']); + if (!empty($params)) { + $params = array_replace($query, $params); $queryString = http_build_query($query, '', '&'); } else { - $options['param'] = $query; + $params = $query; $queryString = $info['query']; } - } elseif (isset($options['param'])) { - $queryString = http_build_query($options['param'], '', '&'); + } elseif (!empty($params)) { + $queryString = http_build_query($params, '', '&'); } $server['REQUEST_URI'] = $info['path'] . ('' !== $queryString ? '?' . $queryString : ''); $server['QUERY_STRING'] = $queryString; $options['cookie'] = $cookie; + $options['param'] = $params; $options['file'] = $files; $options['server'] = $server; $options['url'] = $server['REQUEST_URI']; @@ -554,6 +554,11 @@ class Request */ public function param($name = '', $default = null) { + if(is_array($name)){ + // 设置param + $this->param = array_merge($this->param, $name); + return; + } if (empty($this->param)) { $method = $this->method(true); // 自动获取请求变量 diff --git a/library/think/Route.php b/library/think/Route.php index 3e3a2b63..497d2b41 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1178,7 +1178,7 @@ class Route } /** - * 解析URL地址中的参数到$_GET + * 解析URL地址中的参数Request对象 * @access private * @param string $rule 路由规则 * @param array $var 变量 @@ -1195,7 +1195,9 @@ class Route }, $url); } } - $_GET = array_merge($var, $_GET); + + // 设置当前请求的参数 + Request::instance()->param(array_merge($var, $_GET)); } }