mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进Request的param方法和Route类的parseUrlParams方法
This commit is contained in:
@@ -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);
|
||||
// 自动获取请求变量
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user