From a981277c665dabc19f47e569ccbb6256fbb3d4a2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 21 Dec 2016 12:22:24 +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=E8=B0=83=E7=94=A8=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index dc7002d7..52f46516 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1187,8 +1187,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess */ public static function useGlobalScope($use) { - $model = new static(); - self::$db = $model->db($use); + $model = new static(); + static::$db = $model->db($use); return $model; } @@ -1460,10 +1460,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public function __call($method, $args) { if (isset(static::$db)) { - $query = static::$db; + $query = static::$db; + static::$db = null; } else { $query = $this->db(); } + if (method_exists($this, 'scope' . $method)) { // 动态调用命名范围 $method = 'scope' . $method; @@ -1478,7 +1480,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public static function __callStatic($method, $params) { if (isset(static::$db)) { - $query = static::$db; + $query = static::$db; + static::$db = null; } else { $query = (new static())->db(); }