From 3191ffda86a07e287073ef66ddabc44ca83857a4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 2 Jan 2016 21:11:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0APP=5FMULTI=5FMODULE=E5=B8=B8?= =?UTF-8?q?=E9=87=8F=20=E7=94=A8=E4=BA=8E=E8=AE=BE=E7=BD=AE=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=A4=9A=E6=A8=A1=E5=9D=97=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 1 + library/think/app.php | 6 +++--- library/think/build.php | 1 + library/think/loader.php | 2 +- library/think/route.php | 4 ++-- library/think/url.php | 2 +- library/think/view.php | 4 ++-- 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/base.php b/base.php index 24a8cda8..63a061b1 100644 --- a/base.php +++ b/base.php @@ -36,6 +36,7 @@ defined('EXT') or define('EXT', '.php'); defined('MODEL_LAYER') or define('MODEL_LAYER', 'model'); defined('VIEW_LAYER') or define('VIEW_LAYER', 'view'); defined('CONTROLLER_LAYER') or define('CONTROLLER_LAYER', 'controller'); +defined('APP_MULTI_MODULE') or define('APP_MULTI_MODULE', true); // 是否多模块 defined('APP_DEBUG') or define('APP_DEBUG', false); // 是否调试模式 defined('APP_HOOK') or define('APP_HOOK', false); // 是否开启HOOK defined('ENV_PREFIX') or define('ENV_PREFIX', 'T_'); // 环境变量的配置前缀 diff --git a/library/think/app.php b/library/think/app.php index 4d2f964f..e4bfc917 100644 --- a/library/think/app.php +++ b/library/think/app.php @@ -195,7 +195,7 @@ class App private static function initModule($module, $config) { // 定位模块目录 - $module = COMMON_MODULE == $module ? '' : $module . DS; + $module = (COMMON_MODULE == $module || !APP_MULTI_MODULE) ? '' : $module . DS; // 加载初始化文件 if (is_file(APP_PATH . $module . 'init' . EXT)) { @@ -323,8 +323,8 @@ class App } } - $module = strtolower($result[0] ?: $config['default_module']); - if ($module) { + if (APP_MULTI_MODULE) { + $module = strtolower($result[0] ?: $config['default_module']); if ($maps = $config['url_module_map']) { if (isset($maps[$module])) { // 记录当前别名 diff --git a/library/think/build.php b/library/think/build.php index 32df310a..1b4d8f0b 100644 --- a/library/think/build.php +++ b/library/think/build.php @@ -65,6 +65,7 @@ class Build // 创建模块 protected static function buildModule($module, $list) { + $module = APP_MULTI_MODULE ? $module : ''; if (!is_dir(APP_PATH . $module)) { // 创建模块目录 mkdir(APP_PATH . $module); diff --git a/library/think/loader.php b/library/think/loader.php index 8715da81..11a1310a 100644 --- a/library/think/loader.php +++ b/library/think/loader.php @@ -398,6 +398,6 @@ class Loader */ public static function parseClass($module, $layer, $name) { - return APP_NAMESPACE . '\\' . ($module ? $module . '\\' : '') . $layer . '\\' . self::parseName(str_replace('/', '\\', $name), 1); + return APP_NAMESPACE . '\\' . (APP_MULTI_MODULE ? $module . '\\' : '') . $layer . '\\' . self::parseName(str_replace('/', '\\', $name), 1); } } diff --git a/library/think/route.php b/library/think/route.php index 5fd66a8c..48f04574 100644 --- a/library/think/route.php +++ b/library/think/route.php @@ -467,13 +467,13 @@ class Route } // 解析[模块/控制器/操作] if ($reverse) { - $module = array_shift($path); + $module = APP_MULTI_MODULE ? array_shift($path) : null; $controller = !empty($path) ? array_shift($path) : null; $action = !empty($path) ? array_shift($path) : null; } else { $action = array_pop($path); $controller = !empty($path) ? array_pop($path) : null; - $module = !empty($path) ? array_pop($path) : null; + $module = APP_MULTI_MODULE && !empty($path) ? array_pop($path) : null; } $action = '[rest]' == $action ? REQUEST_METHOD : $action; $route = [$module, $controller, $action]; diff --git a/library/think/url.php b/library/think/url.php index 10c52382..f04b82fb 100644 --- a/library/think/url.php +++ b/library/think/url.php @@ -52,7 +52,7 @@ class Url if (!defined('BIND_CONTROLLER')) { $var['controller'] = !empty($path) ? array_pop($path) : CONTROLLER_NAME; } - if (!defined('BIND_MODULE')) { + if (APP_MULTI_MODULE && !defined('BIND_MODULE')) { if (!empty($path)) { $var['module'] = array_pop($path); } elseif (MODULE_NAME) { diff --git a/library/think/view.php b/library/think/view.php index 1044e815..0e3fab23 100644 --- a/library/think/view.php +++ b/library/think/view.php @@ -250,7 +250,7 @@ class View } elseif (Cookie::get('think_theme')) { $theme = Cookie::get('think_theme'); } - if (!is_dir(APP_PATH . ($module ? $module . DS : '') . $this->config['view_layer'] . DS . $theme)) { + if (!is_dir(APP_PATH . (APP_MULTI_MODULE ? $module . DS : '') . $this->config['view_layer'] . DS . $theme)) { $theme = $this->config['default_theme']; } Cookie::set('think_theme', $theme, 864000); @@ -276,7 +276,7 @@ class View $tmplPath = $this->config['view_path']; // 模块设置独立的视图目录 if (!$tmplPath) { // 定义TMPL_PATH 则改变全局的视图目录到模块之外 - $tmplPath = defined('TMPL_PATH') ? TMPL_PATH . $module . DS : APP_PATH . ($module ? $module . DS : '') . $this->config['view_layer'] . DS; + $tmplPath = defined('TMPL_PATH') ? TMPL_PATH . $module . DS : APP_PATH . (APP_MULTI_MODULE ? $module . DS : '') . $this->config['view_layer'] . DS; } return $tmplPath . $theme; }