From 01cc676a7a791dd45fe0df6c1899501c3717749d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 11 Dec 2015 08:23:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3M=E5=87=BD=E6=95=B0=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E5=8C=96=E9=97=AE=E9=A2=98=20D=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=AE=9E=E4=BE=8B=E5=8C=96=E5=85=AC=E5=85=B1?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/loader.php | 8 ++++++-- library/think/model.php | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/library/think/loader.php b/library/think/loader.php index dfc4b138..bcde291d 100644 --- a/library/think/loader.php +++ b/library/think/loader.php @@ -149,13 +149,17 @@ class Loader return $_model[$name . $layer]; } if (strpos($name, '/')) { - list($module, $name) = explode('/', $name); + list($module, $name) = explode('/', $name, 2); } else { $module = MODULE_NAME; } - $class = $module . '\\' . $layer . '\\' . self::parseName(str_replace('.', '\\', $name), 1); + $class = $module . '\\' . $layer . '\\' . self::parseName(str_replace('/', '\\', $name), 1); if (class_exists($class)) { $model = new $class($name); + } elseif (false === strpos($name, '/')) { + // 自动加载公共模块下面的模型 + $class = COMMON_MODULE . strstr($class, '\\'); + $model = class_exists($class) ? new $class($name) : new Model($name); } else { Log::record('实例化不存在的类:' . $class, 'NOTIC'); $model = new Model($name); diff --git a/library/think/model.php b/library/think/model.php index c769df1f..30f7d993 100644 --- a/library/think/model.php +++ b/library/think/model.php @@ -50,7 +50,6 @@ class Model /** * 架构函数 - * 取得DB类的实例对象 字段检查 * @access public * @param string $name 模型名称 * @param array $config 模型配置 @@ -70,21 +69,21 @@ class Model list($this->dbName, $this->name) = explode('.', $this->name); } - if (isset($config['prefix'])) { + if (!empty($config['prefix'])) { $this->tablePrefix = $config['prefix']; } else { $this->tablePrefix = Config::get('database.prefix'); } - if (isset($config['connection'])) { + if (!empty($config['connection'])) { $this->connection = $config['connection']; } - if (isset($config['table_name'])) { + if (!empty($config['table_name'])) { $this->tableName = $config['table_name']; } - if (isset($config['true_table_name'])) { + if (!empty($config['true_table_name'])) { $this->trueTableName = $config['true_table_name']; } - if (isset($config['db_name'])) { + if (!empty($config['db_name'])) { $this->dbName = $config['db_name']; } @@ -999,7 +998,7 @@ class Model } return $this; } - + /** * 查询SQL组装 join * @access public @@ -1010,7 +1009,10 @@ class Model */ public function join($join, $condition = null, $type = 'INNER') { - if (empty($join)) return $this; + if (empty($join)) { + return $this; + } + if (empty($condition)) { if (is_array($join) && is_array($join[0])) { // 如果为组数,则循环调用join @@ -1023,7 +1025,7 @@ class Model $this->_join($join, $condition); // 兼容原来的join写法 } } elseif (in_array(strtoupper($condition), array('INNER', 'LEFT', 'RIGHT', 'ALL'))) { - $this->_join($join, $condition); // 兼容原来的join写法 + $this->_join($join, $condition); // 兼容原来的join写法 } else { $prefix = $this->tablePrefix; // 传入的表名为数组 @@ -1065,7 +1067,6 @@ class Model return $this; } - /** * 查询SQL组装 union * @access public