From 0f5151dde445773cdd5bd9fbc8e289004534b113 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Sep 2016 11:37:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0getDb=E9=9D=99=E6=80=81=E6=96=B9=E6=B3=95=E8=8E=B7?= =?UTF-8?q?=E5=8F=96db=E6=9F=A5=E8=AF=A2=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 276f4770..0f7d72d3 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1346,11 +1346,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public static function __callStatic($method, $params) { - $model = get_called_class(); - if (!isset(self::$links[$model])) { - self::$links[$model] = (new static())->db(); - } - $query = self::$links[$model]; + $query = self::getDb(); // 全局作用域 if (static::$useGlobalScope && method_exists($model, 'base')) { call_user_func_array('static::base', [ & $query]); @@ -1358,6 +1354,15 @@ abstract class Model implements \JsonSerializable, \ArrayAccess return call_user_func_array([$query, $method], $params); } + protected static function getDb() + { + $model = get_called_class(); + if (!isset(self::$links[$model])) { + self::$links[$model] = (new static())->db(); + } + return self::$links[$model]; + } + /** * 修改器 设置数据对象的值 * @access public