mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
增加url_param_type配置参数 用于配置操作方法的参数绑定方式
This commit is contained in:
@@ -63,14 +63,14 @@ return [
|
|||||||
'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'],
|
'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'],
|
||||||
// pathinfo分隔符
|
// pathinfo分隔符
|
||||||
'pathinfo_depr' => '/',
|
'pathinfo_depr' => '/',
|
||||||
// 获取当前页面地址的系统变量 默认为REQUEST_URI
|
|
||||||
'url_request_uri' => 'REQUEST_URI',
|
|
||||||
// URL伪静态后缀
|
// URL伪静态后缀
|
||||||
'url_html_suffix' => 'html',
|
'url_html_suffix' => 'html',
|
||||||
// URL普通方式参数 用于自动生成
|
// URL普通方式参数 用于自动生成
|
||||||
'url_common_param' => false,
|
'url_common_param' => false,
|
||||||
//url禁止访问的后缀
|
//url禁止访问的后缀
|
||||||
'url_deny_suffix' => 'ico|png|gif|jpg',
|
'url_deny_suffix' => 'ico|png|gif|jpg',
|
||||||
|
// URL参数方式 0 按名称成对解析 1 按顺序解析
|
||||||
|
'url_param_type' => 0,
|
||||||
// 是否开启路由
|
// 是否开启路由
|
||||||
'url_route_on' => true,
|
'url_route_on' => true,
|
||||||
// 是否强制使用路由
|
// 是否强制使用路由
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ function trace($log = '[think]', $level = 'log')
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前Request对象实例
|
* 获取当前Request对象实例
|
||||||
* @return \think\Request
|
* @return Request
|
||||||
*/
|
*/
|
||||||
function request()
|
function request()
|
||||||
{
|
{
|
||||||
@@ -349,7 +349,7 @@ function request()
|
|||||||
* @param mixed $data 输出数据
|
* @param mixed $data 输出数据
|
||||||
* @param string $type 输出类型
|
* @param string $type 输出类型
|
||||||
* @param array $options 参数
|
* @param array $options 参数
|
||||||
* @return \think\Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
function response($data = [], $type = '', $options = [])
|
function response($data = [], $type = '', $options = [])
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -389,7 +389,7 @@ class App
|
|||||||
}
|
}
|
||||||
if (false === $result) {
|
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正常取值
|
||||||
$_REQUEST = array_merge($_POST, $_GET, $_COOKIE);
|
$_REQUEST = array_merge($_POST, $_GET, $_COOKIE);
|
||||||
|
|||||||
@@ -827,9 +827,10 @@ class Route
|
|||||||
* @param string $url URL地址
|
* @param string $url URL地址
|
||||||
* @param string $depr URL分隔符
|
* @param string $depr URL分隔符
|
||||||
* @param bool $autoSearch 是否自动深度搜索控制器
|
* @param bool $autoSearch 是否自动深度搜索控制器
|
||||||
|
* @param integer $paramType URL参数解析方式 0 名称解析 1 顺序解析
|
||||||
* @return array
|
* @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'])) {
|
if (isset(self::$bind['module'])) {
|
||||||
// 如果有模块/控制器绑定
|
// 如果有模块/控制器绑定
|
||||||
@@ -840,7 +841,7 @@ class Route
|
|||||||
$url = str_replace($depr, '/', $url);
|
$url = str_replace($depr, '/', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = self::parseRoute($url, $autoSearch, true);
|
$result = self::parseRoute($url, $autoSearch, true, $paramType);
|
||||||
|
|
||||||
if (!empty($result['var'])) {
|
if (!empty($result['var'])) {
|
||||||
$_GET = array_merge($result['var'], $_GET);
|
$_GET = array_merge($result['var'], $_GET);
|
||||||
@@ -854,9 +855,10 @@ class Route
|
|||||||
* @param string $url URL地址
|
* @param string $url URL地址
|
||||||
* @param bool $autoSearch 是否自动深度搜索控制器
|
* @param bool $autoSearch 是否自动深度搜索控制器
|
||||||
* @param bool $reverse 是否反转解析URL
|
* @param bool $reverse 是否反转解析URL
|
||||||
|
* @param integer $paramType URL参数解析方式 0 名称解析 1 顺序解析
|
||||||
* @return array
|
* @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, '/');
|
$url = trim($url, '/');
|
||||||
$var = [];
|
$var = [];
|
||||||
@@ -901,9 +903,13 @@ class Route
|
|||||||
$action = !empty($path) ? array_shift($path) : null;
|
$action = !empty($path) ? array_shift($path) : null;
|
||||||
// 解析额外参数
|
// 解析额外参数
|
||||||
if (!empty($path)) {
|
if (!empty($path)) {
|
||||||
preg_replace_callback('/([^\/]+)\/([^\/]+)/', function ($match) use (&$var) {
|
if ($paramType) {
|
||||||
$var[strtolower($match[1])] = strip_tags($match[2]);
|
$var += $path;
|
||||||
}, implode('/', $path));
|
} else {
|
||||||
|
preg_replace_callback('/([^\/]+)\/([^\/]+)/', function ($match) use (&$var) {
|
||||||
|
$var[strtolower($match[1])] = strip_tags($match[2]);
|
||||||
|
}, implode('/', $path));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$action = array_pop($path);
|
$action = array_pop($path);
|
||||||
|
|||||||
Reference in New Issue
Block a user