增加url_param_type配置参数 用于配置操作方法的参数绑定方式

This commit is contained in:
thinkphp
2016-06-01 14:13:21 +08:00
parent 3420eb5f60
commit dfa5143dad
4 changed files with 17 additions and 11 deletions

View File

@@ -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,
// 是否强制使用路由

View File

@@ -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 = [])
{

View File

@@ -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);

View File

@@ -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);