From 57fe06a11b4e040901297937b0387716d050d1f3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 6 Dec 2016 07:52:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB=E7=9A=84useGlo?= =?UTF-8?q?balScope=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 68688759..404e63de 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -113,6 +113,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected $batchValidate = false; // 查询数据集对象 protected $resultSetType; + // + protected static $db; /** * 初始化过的模型. @@ -1149,8 +1151,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess */ public static function useGlobalScope($use) { - $model = new static(); - $model->useGlobalScope = $use; + $model = new static(); + self::$db = $model->db($use); return $model; } @@ -1433,7 +1435,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public static function __callStatic($method, $params) { - $query = (new static())->db(); + if (isset(static::$db)) { + $query = static::$db; + } else { + $query = (new static())->db(); + } + return call_user_func_array([$query, $method], $params); }