mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 15:42:48 +08:00
改进模型类的get和all方法 第二个参数为true或者数字表示缓存参数
This commit is contained in:
@@ -189,7 +189,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
}
|
}
|
||||||
// 全局作用域
|
// 全局作用域
|
||||||
if ($baseQuery && method_exists($this, 'base')) {
|
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];
|
return self::$links[$model];
|
||||||
@@ -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);
|
||||||
@@ -1219,7 +1219,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
if (isset(self::$event[$this->class][$event])) {
|
if (isset(self::$event[$this->class][$event])) {
|
||||||
foreach (self::$event[$this->class][$event] as $callback) {
|
foreach (self::$event[$this->class][$event] as $callback) {
|
||||||
if (is_callable($callback)) {
|
if (is_callable($callback)) {
|
||||||
$result = call_user_func_array($callback, [& $params]);
|
$result = call_user_func_array($callback, [ & $params]);
|
||||||
if (false === $result) {
|
if (false === $result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -1309,7 +1317,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$result = $result->where($data);
|
$result = $result->where($data);
|
||||||
$data = null;
|
$data = null;
|
||||||
} elseif ($data instanceof \Closure) {
|
} elseif ($data instanceof \Closure) {
|
||||||
call_user_func_array($data, [& $result]);
|
call_user_func_array($data, [ & $result]);
|
||||||
$data = null;
|
$data = null;
|
||||||
} elseif ($data instanceof Query) {
|
} elseif ($data instanceof Query) {
|
||||||
$result = $data->with($with)->cache($cache);
|
$result = $data->with($with)->cache($cache);
|
||||||
@@ -1332,7 +1340,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$query->where($data);
|
$query->where($data);
|
||||||
$data = null;
|
$data = null;
|
||||||
} elseif ($data instanceof \Closure) {
|
} elseif ($data instanceof \Closure) {
|
||||||
call_user_func_array($data, [& $query]);
|
call_user_func_array($data, [ & $query]);
|
||||||
$data = null;
|
$data = null;
|
||||||
} elseif (is_null($data)) {
|
} elseif (is_null($data)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user