\app\myadmin\modelmenu

Class Model

Summary

Methods
Properties
Constants
__construct()
getName()
readMaster()
newInstance()
setQuery()
db()
force()
isForce()
replace()
exists()
isExists()
isEmpty()
save()
setInc()
setDec()
saveAll()
isUpdate()
delete()
auto()
create()
update()
destroy()
getError()
__wakeup()
__debugInfo()
__set()
__get()
__isset()
__unset()
offsetSet()
offsetExists()
offsetUnset()
offsetGet()
useGlobalScope()
__call()
__callStatic()
getPk()
getKey()
allowField()
readonly()
data()
appendData()
getOrigin()
getData()
getChangedData()
setAttr()
isAutoWriteTimestamp()
getAttr()
withAttribute()
setParent()
getParent()
getRelation()
setRelation()
bindAttr()
together()
has()
hasWhere()
relationQuery()
eagerlyResultSet()
eagerlyResult()
relationCount()
hasOne()
belongsTo()
hasMany()
hasManyThrough()
belongsToMany()
morphOne()
morphMany()
morphTo()
event()
flushEvent()
observe()
withEvent()
append()
appendRelationAttr()
hidden()
visible()
toArray()
toJson()
removeRelation()
__toString()
jsonSerialize()
toCollection()
index()
edit()
scope()
where()
whereRaw()
whereExp()
when()
join()
view()
with()
count()
min()
max()
sum()
avg()
field()
fieldRaw()
union()
limit()
order()
orderRaw()
cache()
value()
column()
find()
findOrFail()
Collection()
get()
getOrFail()
findOrEmpty()
Collection()
withAttr()
withJoin()
withCount()
withSum()
withMax()
withMin()
withAvg()
paginate()
No public properties found
No constants found
buildQuery()
initialize()
init()
autoCompleteData()
checkBeforeSave()
checkAllowFields()
updateData()
insertData()
getWhere()
isPk()
autoWriteTimestamp()
writeTransform()
getRelationAttribute()
readTransform()
parseModel()
getForeignKey()
isRelationAttr()
getRelationData()
checkAutoRelationWrite()
autoRelationUpdate()
autoRelationInsert()
autoRelationDelete()
trigger()
beforeInsert()
afterInsert()
beforeUpdate()
afterUpdate()
beforeWrite()
afterWrite()
beforeDelete()
afterDelete()
beforeRestore()
afterRestore()
formatDateTime()
checkTimeStampWrite()
$connection
$query
$name
$table
$auto
$insert
$update
$initialized
$readMaster
$queryInstance
$error
$defaultSoftDelete
$globalScope
$pk
$field
$json
$jsonAssoc
$jsonType
$disuse
$readonly
$type
$relationWrite
$observe
$observerClass
$autoWriteTimestamp
$createTime
$updateTime
$dateFormat
$visible
$hidden
$append
$resultSetType
N/A
buildMenuChild()
$exists
$replace
$force
$updateWhere
$data
$set
$origin
$withAttr
$parent
$relation
$together
$event
$withEvent
N/A

Properties

$connection

$connection : array|string

数据库配置信息

Type

array|string

$query

$query : string

数据库查询对象类名

Type

string

$name

$name : string

模型名称

Type

string

$table

$table : string

数据表名称

Type

string

$auto

$auto : array

写入自动完成定义

Type

array

$insert

$insert : array

新增自动完成定义

Type

array

$update

$update : array

更新自动完成定义

Type

array

$initialized

$initialized : array

初始化过的模型.

Type

array

$readMaster

$readMaster : array

是否从主库读取(主从分布式有效)

Type

array

$queryInstance

$queryInstance : \think\db\Query

查询对象实例

Type

Query

$error

$error : mixed

错误信息

Type

mixed

$defaultSoftDelete

$defaultSoftDelete : mixed

软删除字段默认值

Type

mixed

$globalScope

$globalScope : array

全局查询范围

Type

array

$pk

$pk : string|array

数据表主键 复合主键使用数组定义

Type

string|array

$field

$field : array

数据表字段信息 留空则自动获取

Type

array

$json

$json : array

JSON数据表字段

Type

array

$jsonAssoc

$jsonAssoc : bool

JSON数据取出是否需要转换为数组

Type

bool

$jsonType

$jsonType : array

JSON数据表字段类型

Type

array

$disuse

$disuse : array

数据表废弃字段

Type

array

$readonly

$readonly : array

数据表只读字段

Type

array

$type

$type : array

数据表字段类型

Type

array

$relationWrite

$relationWrite : array

关联自动写入信息

Type

array

$observe

$observe : array

模型事件观察

Type

array

$observerClass

$observerClass : array

绑定模型事件观察者类

Type

array

$autoWriteTimestamp

$autoWriteTimestamp

$createTime

$createTime

$updateTime

$updateTime

$dateFormat

$dateFormat : string

时间字段显示格式

Type

string

$visible

$visible : array

数据输出显示的属性

Type

array

$hidden

$hidden : array

数据输出隐藏的属性

Type

array

$append

$append : array

数据输出需要追加的属性

Type

array

$resultSetType

$resultSetType : string

数据集对象名

Type

string

$exists

$exists : bool

是否存在数据

Type

bool

$replace

$replace : bool

是否Replace

Type

bool

$force

$force : bool

是否强制更新所有数据

Type

bool

$updateWhere

$updateWhere : array

更新条件

Type

array

$data

$data : array

当前模型数据

Type

array

$set

$set : array

修改器执行记录

Type

array

$origin

$origin : array

原始数据

Type

array

$withAttr

$withAttr : array

动态获取器

Type

array

$parent

$parent : object

父关联模型对象

Type

object

$relation

$relation : array

模型关联数据

Type

array

$together

$together : array

关联写入定义信息

Type

array

$event

$event : array

模型回调

Type

array

$withEvent

$withEvent : bool

是否需要事件响应

Type

bool

Methods

__construct()

__construct(array|object  $data = []) : mixed

架构函数

Parameters

array|object $data

数据

Returns

mixed —

getName()

getName() : string

获取当前模型名称

Returns

string —

readMaster()

readMaster(bool  $all = false) : $this

是否从主库读取数据(主从分布有效)

Parameters

bool $all

是否所有模型有效

Returns

$this —

newInstance()

newInstance(array|object  $data = [], bool  $isUpdate = false, mixed  $where = null) : \think\Model

创建新的模型实例

Parameters

array|object $data

数据

bool $isUpdate

是否为更新

mixed $where

更新条件

Returns

\think\Model —

setQuery()

setQuery(\think\db\Query  $query) : $this

获取当前模型的数据库查询对象

Parameters

\think\db\Query $query

查询对象实例

Returns

$this —

db()

db(bool|array  $useBaseQuery = true) : \think\db\Query

获取当前模型的数据库查询对象

Parameters

bool|array $useBaseQuery

是否调用全局查询范围(或者指定查询范围名称)

Returns

\think\db\Query —

force()

force(bool  $force = true) : $this

更新是否强制写入数据 而不做比较

Parameters

bool $force

Returns

$this —

isForce()

isForce() : bool

判断force

Returns

bool —

replace()

replace(bool  $replace = true) : $this

新增数据是否使用Replace

Parameters

bool $replace

Returns

$this —

exists()

exists(bool  $exists) : $this

设置数据是否存在

Parameters

bool $exists

Returns

$this —

isExists()

isExists() : bool

判断数据是否存在数据库

Returns

bool —

isEmpty()

isEmpty() : bool

判断模型是否为空

Returns

bool —

save()

save(array  $data = [], array  $where = [], string  $sequence = null) : bool

保存当前数据对象

Parameters

array $data

数据

array $where

更新条件

string $sequence

自增序列名

Returns

bool —

setInc()

setInc(string  $field, int  $step = 1, int  $lazyTime) : bool

字段值(延迟)增长

Parameters

string $field

字段名

int $step

增长值

int $lazyTime

延时时间(s)

Throws

\think\Exception

Returns

bool —

setDec()

setDec(string  $field, int  $step = 1, int  $lazyTime) : bool

字段值(延迟)减少

Parameters

string $field

字段名

int $step

减少值

int $lazyTime

延时时间(s)

Throws

\think\Exception

Returns

bool —

saveAll()

saveAll(array  $dataSet, bool  $replace = true) : \think\Collection

保存多个数据到当前数据对象

Parameters

array $dataSet

数据

bool $replace

是否自动识别更新和写入

Throws

\Exception

Returns

\think\Collection —

isUpdate()

isUpdate(mixed  $update = true, mixed  $where = null) : $this

是否为更新数据

Parameters

mixed $update
mixed $where

Returns

$this —

delete()

delete() : bool

删除当前的记录

Returns

bool —

auto()

auto(array  $fields) : $this

设置自动完成的字段( 规则通过修改器定义)

Parameters

array $fields

需要自动完成的字段

Returns

$this —

create()

create(array  $data = [], array|true  $field = null, bool  $replace = false) : static

写入数据

Parameters

array $data

数据数组

array|true $field

允许字段

bool $replace

使用Replace

Returns

static —

update()

update(array  $data = [], array  $where = [], array|true  $field = null) : static

更新数据

Parameters

array $data

数据数组

array $where

更新条件

array|true $field

允许字段

Returns

static —

destroy()

destroy(mixed  $data) : bool

删除记录

Parameters

mixed $data

主键列表 支持闭包查询条件

Returns

bool —

getError()

getError() : mixed

获取错误信息

Returns

mixed —

__wakeup()

__wakeup() : mixed

解序列化后处理

Returns

mixed —

__debugInfo()

__debugInfo() : mixed

Returns

mixed —

__set()

__set(string  $name, mixed  $value) : void

修改器 设置数据对象的值

Parameters

string $name

名称

mixed $value

__get()

__get(string  $name) : mixed

获取器 获取数据对象的值

Parameters

string $name

名称

Returns

mixed —

__isset()

__isset(string  $name) : bool

检测数据对象的值

Parameters

string $name

名称

Returns

bool —

__unset()

__unset(string  $name) : void

销毁数据对象的值

Parameters

string $name

名称

offsetSet()

offsetSet(mixed  $name, mixed  $value) : mixed

Parameters

mixed $name
mixed $value

Returns

mixed —

offsetExists()

offsetExists(mixed  $name) : mixed

Parameters

mixed $name

Returns

mixed —

offsetUnset()

offsetUnset(mixed  $name) : mixed

Parameters

mixed $name

Returns

mixed —

offsetGet()

offsetGet(mixed  $name) : mixed

Parameters

mixed $name

Returns

mixed —

useGlobalScope()

useGlobalScope(bool|array  $use) : \think\db\Query

设置是否使用全局查询范围

Parameters

bool|array $use

是否启用全局查询范围(或者用数组指定查询范围名称)

Returns

\think\db\Query —

__call()

__call(mixed  $method, mixed  $args) : mixed

Parameters

mixed $method
mixed $args

Returns

mixed —

__callStatic()

__callStatic(mixed  $method, mixed  $args) : mixed

Parameters

mixed $method
mixed $args

Returns

mixed —

getPk()

getPk() : string|array

获取模型对象的主键

Returns

string|array —

getKey()

getKey() : int

获取模型对象的主键值

Returns

int —

allowField()

allowField(array|string|true  $field) : $this

设置允许写入的字段

Parameters

array|string|true $field

允许写入的字段 如果为true只允许写入数据表字段

Returns

$this —

readonly()

readonly(array|string  $field) : $this

设置只读字段

Parameters

array|string $field

只读字段

Returns

$this —

data()

data(mixed  $data, mixed  $value = null) : $this

设置数据对象值

Parameters

mixed $data

数据或者属性名

mixed $value

Returns

$this —

appendData()

appendData(mixed  $data, bool  $set = false) : $this

批量设置数据对象值

Parameters

mixed $data

数据

bool $set

是否需要进行数据处理

Returns

$this —

getOrigin()

getOrigin(string  $name = null) : mixed

获取对象原始数据 如果不存在指定字段返回null

Parameters

string $name

字段名 留空获取全部

Returns

mixed —

getData()

getData(string  $name = null) : mixed

获取对象原始数据 如果不存在指定字段返回false

Parameters

string $name

字段名 留空获取全部

Throws

\InvalidArgumentException

Returns

mixed —

getChangedData()

getChangedData() : array

获取变化的数据 并排除只读数据

Returns

array —

setAttr()

setAttr(string  $name, mixed  $value, array  $data = []) : void

修改器 设置数据对象值

Parameters

string $name

属性名

mixed $value

属性值

array $data

数据

isAutoWriteTimestamp()

isAutoWriteTimestamp(bool  $auto) : $this

是否需要自动写入时间字段

Parameters

bool $auto

Returns

$this —

getAttr()

getAttr(string  $name, array  $item = null) : mixed

获取器 获取数据对象的值

Parameters

string $name

名称

array $item

数据

Throws

\InvalidArgumentException

Returns

mixed —

withAttribute()

withAttribute(string|array  $name, callable  $callback = null) : $this

设置数据字段获取器

Parameters

string|array $name

字段名

callable $callback

闭包获取器

Returns

$this —

setParent()

setParent(\think\Model  $model) : $this

设置父关联对象

Parameters

\think\Model $model

模型对象

Returns

$this —

getParent()

getParent() : \think\Model

获取父关联对象

Returns

\think\Model —

getRelation()

getRelation(string  $name = null) : mixed

获取当前模型的关联模型数据

Parameters

string $name

关联方法名

Returns

mixed —

setRelation()

setRelation(string  $name, mixed  $value, array  $data = []) : $this

设置关联数据对象值

Parameters

string $name

属性名

mixed $value

属性值

array $data

数据

Returns

$this —

bindAttr()

bindAttr(string  $relation, array  $attrs = []) : $this

绑定(一对一)关联属性到当前模型

Parameters

string $relation

关联名称

array $attrs

绑定属性

Throws

\think\Exception

Returns

$this —

together()

together(array|string  $relation) : $this

关联数据写入

Parameters

array|string $relation

关联

Returns

$this —

has()

has(string  $relation, mixed  $operator = '>=', int  $count = 1, string  $id = '*', string  $joinType = 'INNER') : \think\db\Query

根据关联条件查询当前模型

Parameters

string $relation

关联方法名

mixed $operator

比较操作符

int $count

个数

string $id

关联表的统计字段

string $joinType

JOIN类型

Returns

\think\db\Query —

hasWhere()

hasWhere(string  $relation, mixed  $where = [], mixed  $fields = '*') : \think\db\Query

根据关联条件查询当前模型

Parameters

string $relation

关联方法名

mixed $where

查询条件(数组或者闭包)

mixed $fields

字段

Returns

\think\db\Query —

relationQuery()

relationQuery(string|array  $relations, array  $withRelationAttr = []) : $this

查询当前模型的关联数据

Parameters

string|array $relations

关联名

array $withRelationAttr

关联获取器

Returns

$this —

eagerlyResultSet()

eagerlyResultSet(array  $resultSet, string  $relation, array  $withRelationAttr = [], bool  $join = false) : array

预载入关联查询 返回数据集

Parameters

array $resultSet

数据集

string $relation

关联名

array $withRelationAttr

关联获取器

bool $join

是否为JOIN方式

Returns

array —

eagerlyResult()

eagerlyResult(\think\Model  $result, string  $relation, array  $withRelationAttr = [], bool  $join = false) : \think\Model

预载入关联查询 返回模型对象

Parameters

\think\Model $result

数据对象

string $relation

关联名

array $withRelationAttr

关联获取器

bool $join

是否为JOIN方式

Returns

\think\Model —

relationCount()

relationCount(\think\Model  $result, array  $relations, string  $aggregate = 'sum', string  $field = '*') : void

关联统计

Parameters

\think\Model $result

数据对象

array $relations

关联名

string $aggregate

聚合查询方法

string $field

字段

hasOne()

hasOne(string  $model, string  $foreignKey = '', string  $localKey = '') : \think\model\relation\HasOne

HAS ONE 关联定义

Parameters

string $model

模型名

string $foreignKey

关联外键

string $localKey

当前主键

Returns

\think\model\relation\HasOne —

belongsTo()

belongsTo(string  $model, string  $foreignKey = '', string  $localKey = '') : \think\model\relation\BelongsTo

BELONGS TO 关联定义

Parameters

string $model

模型名

string $foreignKey

关联外键

string $localKey

关联主键

Returns

\think\model\relation\BelongsTo —

hasMany()

hasMany(string  $model, string  $foreignKey = '', string  $localKey = '') : \think\model\relation\HasMany

HAS MANY 关联定义

Parameters

string $model

模型名

string $foreignKey

关联外键

string $localKey

当前主键

Returns

\think\model\relation\HasMany —

hasManyThrough()

hasManyThrough(string  $model, string  $through, string  $foreignKey = '', string  $throughKey = '', string  $localKey = '') : \think\model\relation\HasManyThrough

HAS MANY 远程关联定义

Parameters

string $model

模型名

string $through

中间模型名

string $foreignKey

关联外键

string $throughKey

关联外键

string $localKey

当前主键

Returns

\think\model\relation\HasManyThrough —

belongsToMany()

belongsToMany(string  $model, string  $table = '', string  $foreignKey = '', string  $localKey = '') : \think\model\relation\BelongsToMany

BELONGS TO MANY 关联定义

Parameters

string $model

模型名

string $table

中间表名

string $foreignKey

关联外键

string $localKey

当前模型关联键

Returns

\think\model\relation\BelongsToMany —

morphOne()

morphOne(string  $model, string|array  $morph = null, string  $type = '') : \think\model\relation\MorphOne

MORPH One 关联定义

Parameters

string $model

模型名

string|array $morph

多态字段信息

string $type

多态类型

Returns

\think\model\relation\MorphOne —

morphMany()

morphMany(string  $model, string|array  $morph = null, string  $type = '') : \think\model\relation\MorphMany

MORPH MANY 关联定义

Parameters

string $model

模型名

string|array $morph

多态字段信息

string $type

多态类型

Returns

\think\model\relation\MorphMany —

morphTo()

morphTo(string|array  $morph = null, array  $alias = []) : \think\model\relation\MorphTo

MORPH TO 关联定义

Parameters

string|array $morph

多态字段信息

array $alias

多态别名定义

Returns

\think\model\relation\MorphTo —

event()

event(string  $event, callable  $callback, bool  $override = false) : void

注册回调方法

Parameters

string $event

事件名

callable $callback

回调方法

bool $override

是否覆盖

flushEvent()

flushEvent() : void

清除回调方法

observe()

observe(object|string  $class) : void

注册一个模型观察者

Parameters

object|string $class

withEvent()

withEvent(bool  $event) : $this

当前操作的事件响应

Parameters

bool $event

是否需要事件响应

Returns

$this —

append()

append(array  $append = [], bool  $override = false) : $this

设置需要附加的输出属性

Parameters

array $append

属性列表

bool $override

是否覆盖

Returns

$this —

appendRelationAttr()

appendRelationAttr(string  $attr, string|array  $append) : $this

设置附加关联对象的属性

Parameters

string $attr

关联属性

string|array $append

追加属性名

Throws

\think\Exception

Returns

$this —

hidden()

hidden(array  $hidden = [], bool  $override = false) : $this

设置需要隐藏的输出属性

Parameters

array $hidden

属性列表

bool $override

是否覆盖

Returns

$this —

visible()

visible(array  $visible = [], bool  $override = false) : $this

设置需要输出的属性

Parameters

array $visible
bool $override

是否覆盖

Returns

$this —

toArray()

toArray() : array

转换当前模型对象为数组

Returns

array —

toJson()

toJson(int  $options = JSON_UNESCAPED_UNICODE) : string

转换当前模型对象为JSON字符串

Parameters

int $options

json参数

Returns

string —

removeRelation()

removeRelation() : $this

移除当前模型的关联属性

Returns

$this —

__toString()

__toString() : mixed

Returns

mixed —

jsonSerialize()

jsonSerialize() : mixed

Returns

mixed —

toCollection()

toCollection(array|\think\Collection  $collection, string  $resultSetType = null) : \think\Collection

转换数据集为数据集对象

Parameters

array|\think\Collection $collection

数据集

string $resultSetType

数据集类

Returns

\think\Collection —

index()

index(mixed  $where = []) : mixed

Parameters

mixed $where

Returns

mixed —

edit()

edit(mixed  $Int, mixed  $Data) : mixed

Parameters

mixed $Int
mixed $Data

Returns

mixed —

scope()

scope(string|array  $scope) : $this

static 查询范围

Parameters

string|array $scope

Returns

$this —

where()

where(mixed  $field, string  $op = null, mixed  $condition = null) : $this

static 查询条件

Parameters

mixed $field
string $op = null
mixed $condition = null

Returns

$this —

whereRaw()

whereRaw(string  $where, array  $bind = [], string  $logic = 'AND') : $this

static 表达式查询

Parameters

string $where
array $bind = []
string $logic = 'AND'

Returns

$this —

whereExp()

whereExp(string  $field, string  $condition, array  $bind = [], string  $logic = 'AND') : $this

static 字段表达式查询

Parameters

string $field
string $condition
array $bind = []
string $logic = 'AND'

Returns

$this —

when()

when(mixed  $condition, mixed  $query, mixed  $otherwise = null) : $this

static 条件查询

Parameters

mixed $condition
mixed $query
mixed $otherwise = null

Returns

$this —

join()

join(mixed  $join, mixed  $condition = null, string  $type = 'INNER', array  $bind = []) : $this

static JOIN查询

Parameters

mixed $join
mixed $condition = null
string $type = 'INNER'
array $bind = []

Returns

$this —

view()

view(mixed  $join, mixed  $field = null, mixed  $on = null, string  $type = 'INNER') : $this

static 视图查询

Parameters

mixed $join
mixed $field = null
mixed $on = null
string $type = 'INNER'

Returns

$this —

with()

with(mixed  $with, callable  $callback = null) : $this

static 关联预载入

Parameters

mixed $with
callable $callback = null

Returns

$this —

count()

count(string  $field = '*') : $this

static Count统计查询

Parameters

string $field = '*'

Returns

$this —

min()

min(string  $field, bool  $force = true) : $this

static Min统计查询

Parameters

string $field
bool $force = true

Returns

$this —

max()

max(string  $field, bool  $force = true) : $this

static Max统计查询

Parameters

string $field
bool $force = true

Returns

$this —

sum()

sum(string  $field) : $this

static SUM统计查询

Parameters

string $field

Returns

$this —

avg()

avg(string  $field) : $this

static Avg统计查询

Parameters

string $field

Returns

$this —

field()

field(mixed  $field, bool  $except = false, string  $tableName = '', string  $prefix = '', string  $alias = '') : $this

static 指定查询字段

Parameters

mixed $field
bool $except = false
string $tableName = ''
string $prefix = ''
string $alias = ''

Returns

$this —

fieldRaw()

fieldRaw(string  $field) : $this

static 指定查询字段

Parameters

string $field

Returns

$this —

union()

union(mixed  $union, bool  $all = false) : $this

static UNION查询

Parameters

mixed $union
bool $all = false

Returns

$this —

limit()

limit(mixed  $offset, int  $length = null) : $this

static 查询LIMIT

Parameters

mixed $offset
int $length = null

Returns

$this —

order()

order(mixed  $field, string  $order = null) : $this

static 查询ORDER

Parameters

mixed $field
string $order = null

Returns

$this —

orderRaw()

orderRaw(string  $field, array  $bind = []) : $this

static 查询ORDER

Parameters

string $field
array $bind = []

Returns

$this —

cache()

cache(mixed  $key = null, int|\DateTime  $expire = null, string  $tag = null) : $this

static 设置查询缓存

Parameters

mixed $key = null
int|\DateTime $expire = null
string $tag = null

Returns

$this —

value()

value(string  $field, mixed  $default = null) : mixed

static 获取某个字段的值

Parameters

string $field
mixed $default = null

Returns

mixed —

column()

column(string  $field, string  $key = '') : array

static 获取某个列的值

Parameters

string $field
string $key = ''

Returns

array —

find()

find(mixed  $data = null) : $this

static 查询单个记录

Parameters

mixed $data = null

Returns

$this —

findOrFail()

findOrFail(mixed  $data = null) : $this

查询单个记录

Parameters

mixed $data = null

Returns

$this —

Collection()

Collection() : void

|$this[] select(mixed $data = null) static 查询多个记录

get()

get(mixed  $data = null, mixed  $with = [], bool  $cache = false, bool  $failException = false) : $this

static 查询单个记录 支持关联预载入

Parameters

mixed $data = null
mixed $with = []
bool $cache = false
bool $failException = false

Returns

$this —

getOrFail()

getOrFail(mixed  $data = null, mixed  $with = [], bool  $cache = false) : $this

static 查询单个记录 不存在则抛出异常

Parameters

mixed $data = null
mixed $with = []
bool $cache = false

Returns

$this —

findOrEmpty()

findOrEmpty(mixed  $data = null) : $this

static 查询单个记录 不存在则返回空模型

Parameters

mixed $data = null

Returns

$this —

Collection()

Collection() : void

|$this[] all(mixed $data = null, mixed $with = [], bool $cache = false) static 查询多个记录 支持关联预载入

withAttr()

withAttr(array  $name, \Closure  $closure = null) : $this

static 动态定义获取器

Parameters

array $name
\Closure $closure = null

Returns

$this —

withJoin()

withJoin(string|array  $with, string  $joinType = '') : $this

static

Parameters

string|array $with
string $joinType = ''

Returns

$this —

withCount()

withCount(string|array  $relation, bool  $subQuery = true) : $this

static 关联统计

Parameters

string|array $relation
bool $subQuery = true

Returns

$this —

withSum()

withSum(string|array  $relation, string  $field, bool  $subQuery = true) : $this

static 关联SUM统计

Parameters

string|array $relation
string $field
bool $subQuery = true

Returns

$this —

withMax()

withMax(string|array  $relation, string  $field, bool  $subQuery = true) : $this

static 关联MAX统计

Parameters

string|array $relation
string $field
bool $subQuery = true

Returns

$this —

withMin()

withMin(string|array  $relation, string  $field, bool  $subQuery = true) : $this

static 关联Min统计

Parameters

string|array $relation
string $field
bool $subQuery = true

Returns

$this —

withAvg()

withAvg(string|array  $relation, string  $field, bool  $subQuery = true) : $this

static 关联Avg统计

Parameters

string|array $relation
string $field
bool $subQuery = true

Returns

$this —

paginate()

paginate(int|array  $listRows = null, int|bool  $simple = false, array  $config = []) : \think\Paginator|$this

static 分页

Parameters

int|array $listRows = null
int|bool $simple = false
array $config = []

Returns

\think\Paginator|$this —

buildQuery()

buildQuery() : \think\db\Query

创建模型的查询对象

Returns

\think\db\Query —

initialize()

initialize() : void

初始化模型

init()

init() : void

初始化处理

autoCompleteData()

autoCompleteData(array  $auto = []) : void

数据自动完成

Parameters

array $auto

要自动更新的字段列表

checkBeforeSave()

checkBeforeSave(array  $data, array  $where) : bool

写入之前检查数据

Parameters

array $data

数据

array $where

保存条件

Returns

bool —

checkAllowFields()

checkAllowFields(array  $append = []) : array

检查数据是否允许写入

Parameters

array $append

自动完成的字段列表

Returns

array —

updateData()

updateData(mixed  $where) : bool

更新写入数据

Parameters

mixed $where

更新条件

Returns

bool —

insertData()

insertData(string  $sequence) : bool

新增写入数据

Parameters

string $sequence

自增序列名

Returns

bool —

getWhere()

getWhere() : mixed

获取当前的更新条件

Returns

mixed —

isPk()

isPk(string  $key) : bool

判断一个字段名是否为主键字段

Parameters

string $key

名称

Returns

bool —

autoWriteTimestamp()

autoWriteTimestamp(string  $name) : mixed

自动写入时间戳

Parameters

string $name

时间戳字段

Returns

mixed —

writeTransform()

writeTransform(mixed  $value, string|array  $type) : mixed

数据写入 类型转换

Parameters

mixed $value

string|array $type

要转换的类型

Returns

mixed —

getRelationAttribute()

getRelationAttribute(string  $name, array  $item) : mixed

获取关联属性值

Parameters

string $name

属性名

array $item

数据

Returns

mixed —

readTransform()

readTransform(mixed  $value, string|array  $type) : mixed

数据读取 类型转换

Parameters

mixed $value

string|array $type

要转换的类型

Returns

mixed —

parseModel()

parseModel(string  $model) : string

解析模型的完整命名空间

Parameters

string $model

模型名(或者完整类名)

Returns

string —

getForeignKey()

getForeignKey(string  $name) : string

获取模型的默认外键名

Parameters

string $name

模型名

Returns

string —

isRelationAttr()

isRelationAttr(string  $attr) : string|false

检查属性是否为关联属性 如果是则返回关联方法名

Parameters

string $attr

关联属性名

Returns

string|false —

getRelationData()

getRelationData(\think\model\Relation  $modelRelation) : mixed

智能获取关联模型数据

Parameters

\think\model\Relation $modelRelation

模型关联对象

Returns

mixed —

checkAutoRelationWrite()

checkAutoRelationWrite() : void

关联数据自动写入检查

autoRelationUpdate()

autoRelationUpdate() : void

自动关联数据更新(针对一对一关联)

autoRelationInsert()

autoRelationInsert() : void

自动关联数据写入(针对一对一关联)

autoRelationDelete()

autoRelationDelete() : void

自动关联数据删除(支持一对一及一对多关联)

trigger()

trigger(string  $event) : bool

触发事件

Parameters

string $event

事件名

Returns

bool —

beforeInsert()

beforeInsert(callable  $callback, bool  $override = false) : mixed

模型before_insert事件快捷方法

Parameters

callable $callback
bool $override

Returns

mixed —

afterInsert()

afterInsert(callable  $callback, bool  $override = false) : mixed

模型after_insert事件快捷方法

Parameters

callable $callback
bool $override

Returns

mixed —

beforeUpdate()

beforeUpdate(callable  $callback, bool  $override = false) : mixed

模型before_update事件快捷方法

Parameters

callable $callback
bool $override

Returns

mixed —

afterUpdate()

afterUpdate(callable  $callback, bool  $override = false) : mixed

模型after_update事件快捷方法

Parameters

callable $callback
bool $override

Returns

mixed —

beforeWrite()

beforeWrite(callable  $callback, bool  $override = false) : mixed

模型before_write事件快捷方法

Parameters

callable $callback
bool $override

Returns

mixed —

afterWrite()

afterWrite(callable  $callback, bool  $override = false) : mixed

模型after_write事件快捷方法

Parameters

callable $callback
bool $override

Returns

mixed —

beforeDelete()

beforeDelete(callable  $callback, bool  $override = false) : mixed

模型before_delete事件快捷方法

Parameters

callable $callback
bool $override

Returns

mixed —

afterDelete()

afterDelete(callable  $callback, bool  $override = false) : mixed

模型after_delete事件快捷方法

Parameters

callable $callback
bool $override

Returns

mixed —

beforeRestore()

beforeRestore(callable  $callback, bool  $override = false) : mixed

模型before_restore事件快捷方法

Parameters

callable $callback
bool $override

Returns

mixed —

afterRestore()

afterRestore(callable  $callback, bool  $override = false) : mixed

模型after_restore事件快捷方法

Parameters

callable $callback
bool $override

Returns

mixed —

formatDateTime()

formatDateTime(mixed  $format, mixed  $time = 'now', bool  $timestamp = false) : mixed

时间日期字段格式化处理

Parameters

mixed $format

日期格式

mixed $time

时间日期表达式

bool $timestamp

是否进行时间戳转换

Returns

mixed —

checkTimeStampWrite()

checkTimeStampWrite() : void

检查时间字段写入

buildMenuChild()

buildMenuChild(mixed  $pid, mixed  $menuList) : mixed

Parameters

mixed $pid
mixed $menuList

Returns

mixed —