From 8a06e801c8d491915e9464213dd6408273c25ae9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 29 Jan 2017 18:45:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=A8=A1=E5=9E=8B=E7=B1=BB?= =?UTF-8?q?=E7=9A=84get=E5=92=8Call=E6=96=B9=E6=B3=95=20=E7=AC=AC=E4=BA=8C?= =?UTF-8?q?=E4=B8=AA=E5=8F=82=E6=95=B0=E4=B8=BAtrue=E6=88=96=E8=80=85?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E8=A1=A8=E7=A4=BA=E7=BC=93=E5=AD=98=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 085ca053..86fcb88d 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -189,7 +189,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } // 全局作用域 if ($baseQuery && method_exists($this, 'base')) { - call_user_func_array([$this, 'base'], [& self::$links[$model]]); + call_user_func_array([$this, 'base'], [ & self::$links[$model]]); } // 返回当前模型的数据库查询对象 return self::$links[$model]; @@ -326,10 +326,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess break; } } elseif (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), [ - 'datetime', - 'date', - 'timestamp' - ]) + 'datetime', + 'date', + 'timestamp', + ]) ) { $value = $this->formatDateTime($_SERVER['REQUEST_TIME'], $this->dateFormat); } else { @@ -439,10 +439,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = $this->readTransform($value, $this->type[$name]); } elseif (in_array($name, [$this->createTime, $this->updateTime])) { if (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), [ - 'datetime', - 'date', - 'timestamp' - ]) + 'datetime', + 'date', + 'timestamp', + ]) ) { $value = $this->formatDateTime(strtotime($value), $this->dateFormat); } else { @@ -1219,7 +1219,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (isset(self::$event[$this->class][$event])) { foreach (self::$event[$this->class][$event] as $callback) { if (is_callable($callback)) { - $result = call_user_func_array($callback, [& $params]); + $result = call_user_func_array($callback, [ & $params]); if (false === $result) { return false; } @@ -1275,6 +1275,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess */ public static function get($data = null, $with = [], $cache = false) { + if (true === $with || is_int($with)) { + $cache = $with; + $with = []; + } $query = static::parseQuery($data, $with, $cache); return $query->find($data); } @@ -1290,6 +1294,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess */ public static function all($data = null, $with = [], $cache = false) { + if (true === $with || is_int($with)) { + $cache = $with; + $with = []; + } $query = static::parseQuery($data, $with, $cache); return $query->select($data); } @@ -1309,7 +1317,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $result = $result->where($data); $data = null; } elseif ($data instanceof \Closure) { - call_user_func_array($data, [& $result]); + call_user_func_array($data, [ & $result]); $data = null; } elseif ($data instanceof Query) { $result = $data->with($with)->cache($cache); @@ -1332,7 +1340,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $query->where($data); $data = null; } elseif ($data instanceof \Closure) { - call_user_func_array($data, [& $query]); + call_user_func_array($data, [ & $query]); $data = null; } elseif (is_null($data)) { return 0;