改进模型类的get和all方法 第二个参数为true或者数字表示缓存参数

This commit is contained in:
thinkphp
2017-01-29 18:45:56 +08:00
parent 9a308b94e3
commit 8a06e801c8

View File

@@ -328,7 +328,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
} elseif (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), [ } elseif (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), [
'datetime', 'datetime',
'date', 'date',
'timestamp' 'timestamp',
]) ])
) { ) {
$value = $this->formatDateTime($_SERVER['REQUEST_TIME'], $this->dateFormat); $value = $this->formatDateTime($_SERVER['REQUEST_TIME'], $this->dateFormat);
@@ -441,7 +441,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
if (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), [ if (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), [
'datetime', 'datetime',
'date', 'date',
'timestamp' 'timestamp',
]) ])
) { ) {
$value = $this->formatDateTime(strtotime($value), $this->dateFormat); $value = $this->formatDateTime(strtotime($value), $this->dateFormat);
@@ -1275,6 +1275,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
*/ */
public static function get($data = null, $with = [], $cache = false) public static function get($data = null, $with = [], $cache = false)
{ {
if (true === $with || is_int($with)) {
$cache = $with;
$with = [];
}
$query = static::parseQuery($data, $with, $cache); $query = static::parseQuery($data, $with, $cache);
return $query->find($data); return $query->find($data);
} }
@@ -1290,6 +1294,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
*/ */
public static function all($data = null, $with = [], $cache = false) public static function all($data = null, $with = [], $cache = false)
{ {
if (true === $with || is_int($with)) {
$cache = $with;
$with = [];
}
$query = static::parseQuery($data, $with, $cache); $query = static::parseQuery($data, $with, $cache);
return $query->select($data); return $query->select($data);
} }