From d5aeae6b1f718fa49308fccf614d5d524f2ff073 Mon Sep 17 00:00:00 2001 From: devil_gong Date: Thu, 20 Jun 2019 15:21:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=90=8E=E5=8F=B0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin.php | 26 +++++++++++++++++ application/admin/controller/Common.php | 2 +- application/common.php | 37 +++++++++++++++++++++++++ config/app.php | 2 +- public/admin.php | 25 +++++++++++++++++ 5 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 admin.php create mode 100644 public/admin.php diff --git a/admin.php b/admin.php new file mode 100644 index 000000000..fc9d1ac15 --- /dev/null +++ b/admin.php @@ -0,0 +1,26 @@ +bind('admin')->run()->send(); +?> \ No newline at end of file diff --git a/application/admin/controller/Common.php b/application/admin/controller/Common.php index 38144d0db..009acaeaf 100755 --- a/application/admin/controller/Common.php +++ b/application/admin/controller/Common.php @@ -108,7 +108,7 @@ class Common extends Controller ConfigService::ConfigInit(); // url模式,后端采用兼容模式 - \think\facade\Url::root(__MY_ROOT_PUBLIC__.'index.php?s='); + \think\facade\Url::root(__MY_ROOT_PUBLIC__.CurrentScriptName().'?s='); } /** diff --git a/application/common.php b/application/common.php index 65f4f2e12..80203e0db 100755 --- a/application/common.php +++ b/application/common.php @@ -381,6 +381,32 @@ function DataReturn($msg = '', $code = 0, $data = '') return $result; } +/** + * 获取当前脚本名称 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2019-06-20 + * @desc description + */ +function CurrentScriptName() +{ + $name = ''; + if(!empty($_SERVER['SCRIPT_NAME'])) + { + if(!empty($_SERVER['SCRIPT_FILENAME'])) + { + $loc = strripos($_SERVER['SCRIPT_FILENAME'], '/'); + if($loc !== false) + { + $name = substr($_SERVER['SCRIPT_FILENAME'], $loc); + } + } + } else { + $name = $_SERVER['SCRIPT_NAME']; + } + return str_replace('/', '', $name); +} /** * 生成url地址 @@ -394,6 +420,7 @@ function DataReturn($msg = '', $code = 0, $data = '') */ function MyUrl($path, $params=[]) { + // 调用框架生成url $url = url($path, $params, true, true); // 是否根目录访问项目 @@ -408,6 +435,13 @@ function MyUrl($path, $params=[]) $url = 'https'.mb_substr($url, 4, null, 'utf-8'); } + // 避免从后台生成url入口错误 + $script_name = CurrentScriptName(); + if($script_name != 'index.php' && substr($path, 0, 6) == 'index/') + { + $url = str_replace($script_name, 'index.php', $url); + } + return $url; } @@ -444,6 +478,9 @@ function PluginsHomeUrl($plugins_name, $plugins_control, $plugins_action, $param $url = 'https'.mb_substr($url, 4, null, 'utf-8'); } + // 避免从后台生成url入口错误 + $url = str_replace(CurrentScriptName(), 'index.php', $url); + return $url; } diff --git a/config/app.php b/config/app.php index f84fa55bd..3d956197d 100755 --- a/config/app.php +++ b/config/app.php @@ -56,7 +56,7 @@ return [ // 默认模块名 'default_module' => 'index', // 禁止访问模块 - 'deny_module_list' => ['common', 'service'], + 'deny_module_list' => ['common', 'service', 'admin'], // 默认控制器名 'default_controller' => 'index', // 默认操作名 diff --git a/public/admin.php b/public/admin.php new file mode 100644 index 000000000..182b9f94e --- /dev/null +++ b/public/admin.php @@ -0,0 +1,25 @@ +bind('admin')->run()->send(); +?> \ No newline at end of file