From 5e7c8e99021af820d3b6e112b8a858c014d88fb4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 14 Jun 2016 14:57:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88=20MODULE=5FPATH=20=E5=B8=B8?= =?UTF-8?q?=E9=87=8F=20=E7=94=A8=20App::$modulePath=20=E6=9B=BF=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 7 ++++++- library/think/Loader.php | 2 +- library/think/view/driver/Php.php | 5 +++-- library/think/view/driver/Think.php | 5 +++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index 22aa01dc..ffc6f16d 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -34,6 +34,11 @@ class App */ protected static $init = false; + /** + * @var string 当前模块路径 + */ + public static $modulePath; + /** * 执行应用程序 * @access public @@ -232,7 +237,7 @@ class App $module = ''; } // 当前模块路径 - define('MODULE_PATH', APP_PATH . ($module ? $module . DS : '')); + App::$modulePath = APP_PATH . ($module ? $module . DS : ''); // 获取控制器名 $controller = strip_tags($result[1] ?: $config['default_controller']); diff --git a/library/think/Loader.php b/library/think/Loader.php index 6c5cad6a..0cef94b7 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -239,7 +239,7 @@ class Loader $baseUrl = self::$namespace[$name]; } elseif ('@' == $name) { //加载当前模块应用类库 - $baseUrl = MODULE_PATH; + $baseUrl = App::$modulePath; } elseif (is_dir(EXTEND_PATH . $name)) { $baseUrl = EXTEND_PATH; } else { diff --git a/library/think/view/driver/Php.php b/library/think/view/driver/Php.php index 7db03fdb..98660690 100644 --- a/library/think/view/driver/Php.php +++ b/library/think/view/driver/Php.php @@ -11,6 +11,7 @@ namespace think\view\driver; +use think\App; use think\exception\TemplateNotFoundException; use think\Log; use think\Request; @@ -91,8 +92,8 @@ class Php */ private function parseTemplate($template) { - if (empty($this->config['view_path']) && defined('MODULE_PATH')) { - $this->config['view_path'] = MODULE_PATH . 'view' . DS; + if (empty($this->config['view_path'])) { + $this->config['view_path'] = App::$modulePath . 'view' . DS; } if (strpos($template, '@')) { diff --git a/library/think/view/driver/Think.php b/library/think/view/driver/Think.php index 906fcf10..be9a763c 100644 --- a/library/think/view/driver/Think.php +++ b/library/think/view/driver/Think.php @@ -11,6 +11,7 @@ namespace think\view\driver; +use think\App; use think\exception\TemplateNotFoundException; use think\Log; use think\Request; @@ -35,8 +36,8 @@ class Think public function __construct($config = []) { $this->config = array_merge($this->config, $config); - if (empty($this->config['view_path']) && defined('MODULE_PATH')) { - $this->config['view_path'] = MODULE_PATH . 'view' . DS; + if (empty($this->config['view_path'])) { + $this->config['view_path'] = App::$modulePath . 'view' . DS; } $this->template = new Template($this->config); }