优化后台管理地址

This commit is contained in:
devil_gong 2019-06-20 15:21:25 +08:00
parent 148ed5673a
commit d5aeae6b1f
5 changed files with 90 additions and 2 deletions

26
admin.php Normal file
View File

@ -0,0 +1,26 @@
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
// [ 后台入口文件 ]
namespace think;
// 加载基础文件
require __DIR__ . '/thinkphp/base.php';
// 根目录入口
define('IS_ROOT_ACCESS', true);
// 引入公共入口文件
require __DIR__.'/public/core.php';
// 执行应用并响应
Container::get('app')->bind('admin')->run()->send();
?>

View File

@ -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=');
}
/**

View File

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

View File

@ -56,7 +56,7 @@ return [
// 默认模块名
'default_module' => 'index',
// 禁止访问模块
'deny_module_list' => ['common', 'service'],
'deny_module_list' => ['common', 'service', 'admin'],
// 默认控制器名
'default_controller' => 'index',
// 默认操作名

25
public/admin.php Normal file
View File

@ -0,0 +1,25 @@
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
// [ 后台入口文件 ]
namespace think;
// 加载基础文件
require __DIR__ . '/../thinkphp/base.php';
// 支持事先使用静态方法设置Request对象和Config对象
// 引入公共入口文件
require __DIR__.'/core.php';
// 执行应用并响应
Container::get('app')->bind('admin')->run()->send();
?>