\app\admin\modelBlog

Class Model

Summary

Methods
Properties
Constants
__construct()
readMaster()
newInstance()
getQuery()
db()
setParent()
getParent()
data()
getData()
isAutoWriteTimestamp()
force()
setAttr()
getRelation()
setRelation()
getAttr()
append()
appendRelationAttr()
hidden()
visible()
toArray()
toJson()
removeRelation()
toCollection()
together()
getPk()
save()
getChangedData()
setInc()
setDec()
saveAll()
allowField()
except()
readonly()
isUpdate()
delete()
auto()
validate()
validateFailException()
getError()
event()
create()
update()
get()
all()
destroy()
useGlobalScope()
has()
hasWhere()
relationQuery()
eagerlyResultSet()
eagerlyResult()
relationCount()
hasOne()
belongsTo()
hasMany()
hasManyThrough()
belongsToMany()
morphMany()
morphOne()
morphTo()
__call()
__callStatic()
__set()
__get()
__isset()
__unset()
__toString()
jsonSerialize()
offsetSet()
offsetExists()
offsetUnset()
offsetGet()
__wakeup()
getFlagList()
getCustomList()
getStatusList()
getStateList()
getFlagTextAttr()
getCustomTextAttr()
getRefreshtimeTextAttr()
getStatusTextAttr()
getStateTextAttr()
No public properties found
No constants found
buildQuery()
initialize()
init()
autoWriteTimestamp()
formatDateTime()
writeTransform()
getRelationData()
readTransform()
parseAttr()
subToArray()
isPk()
checkAllowField()
autoRelationUpdate()
getWhere()
autoCompleteData()
validateData()
trigger()
parseQuery()
parseModel()
getForeignKey()
beforeInsert()
afterInsert()
beforeUpdate()
afterUpdate()
beforeWrite()
afterWrite()
beforeDelete()
afterDelete()
setFlagAttr()
setCustomAttr()
setRefreshtimeAttr()
$links
$connection
$parent
$query
$name
$table
$class
$error
$validate
$pk
$field
$except
$disuse
$readonly
$visible
$hidden
$append
$data
$origin
$relation
$auto
$insert
$update
$autoWriteTimestamp
$createTime
$updateTime
$dateFormat
$type
$isUpdate
$force
$updateWhere
$failException
$useGlobalScope
$batchValidate
$resultSetType
$relationWrite
$initialized
$readMaster
N/A
No private methods found
$event
N/A

Properties

$links

$links : 

Type

$connection

$connection : 

Type

$parent

$parent : 

Type

$query

$query : 

Type

$name

$name : 

Type

$table

$table : 

Type

$class

$class : 

Type

$error

$error : 

Type

$validate

$validate : 

Type

$pk

$pk : 

Type

$field

$field : 

Type

$except

$except : 

Type

$disuse

$disuse : 

Type

$readonly

$readonly : 

Type

$visible

$visible : 

Type

$hidden

$hidden : 

Type

$append

$append : 

Type

$data

$data : 

Type

$origin

$origin : 

Type

$relation

$relation : 

Type

$auto

$auto : 

Type

$insert

$insert : 

Type

$update

$update : 

Type

$autoWriteTimestamp

$autoWriteTimestamp : 

Type

$createTime

$createTime : 

Type

$updateTime

$updateTime : 

Type

$dateFormat

$dateFormat : 

Type

$type

$type : 

Type

$isUpdate

$isUpdate : 

Type

$force

$force : 

Type

$updateWhere

$updateWhere : 

Type

$failException

$failException : 

Type

$useGlobalScope

$useGlobalScope : 

Type

$batchValidate

$batchValidate : 

Type

$resultSetType

$resultSetType : 

Type

$relationWrite

$relationWrite : 

Type

$initialized

$initialized : array

初始化过的模型.

Type

array

$readMaster

$readMaster : array

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

Type

array

$event

$event : 

Type

Methods

__construct()

__construct(array|object  $data = array()) 

构造方法

Parameters

array|object $data

数据

readMaster()

readMaster(boolean  $all = false) : $this

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

Parameters

boolean $all

是否所有模型生效

Returns

$this

newInstance()

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

创建新的模型实例

Parameters

array|object $data

数据

boolean $isUpdate

是否为更新

mixed $where

更新条件

Returns

\think\Model

getQuery()

getQuery(boolean  $buildNewQuery = false) : \think\db\Query

获取当前模型的查询对象

Parameters

boolean $buildNewQuery

创建新的查询对象

Returns

\think\db\Query

db()

db(boolean  $useBaseQuery = true, boolean  $buildNewQuery = true) : \think\db\Query

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

Parameters

boolean $useBaseQuery

是否调用全局查询范围

boolean $buildNewQuery

创建新的查询对象

Returns

\think\db\Query

setParent()

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

设置父关联对象

Parameters

\think\Model $model

模型对象

Returns

$this

getParent()

getParent() : \think\Model

获取父关联对象

Returns

\think\Model

data()

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

设置数据对象值

Parameters

mixed $data

数据或者属性名

mixed $value

Returns

$this

getData()

getData(string  $name = null) : mixed

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

Parameters

string $name

字段名 留空获取全部

Throws

\InvalidArgumentException

Returns

mixed

isAutoWriteTimestamp()

isAutoWriteTimestamp(boolean  $auto) : $this

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

Parameters

boolean $auto

Returns

$this

force()

force(boolean  $force = true) : $this

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

Parameters

boolean $force

Returns

$this

setAttr()

setAttr(string  $name, mixed  $value, array  $data = array()) : $this

修改器 设置数据对象值

Parameters

string $name

属性名

mixed $value

属性值

array $data

数据

Returns

$this

getRelation()

getRelation(string  $name = null) : mixed

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

Parameters

string $name

关联方法名

Returns

mixed

setRelation()

setRelation(string  $name, mixed  $value) : $this

设置关联数据对象值

Parameters

string $name

属性名

mixed $value

属性值

Returns

$this

getAttr()

getAttr(string  $name) : mixed

获取器 获取数据对象的值

Parameters

string $name

名称

Throws

\InvalidArgumentException

Returns

mixed

append()

append(array  $append = array(), boolean  $override = false) : $this

设置需要追加的输出属性

Parameters

array $append

属性列表

boolean $override

是否覆盖

Returns

$this

appendRelationAttr()

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

设置附加关联对象的属性

Parameters

string $relation

关联方法

string|array $append

追加属性名

Throws

\think\Exception

Returns

$this

hidden()

hidden(array  $hidden = array(), boolean  $override = false) : $this

设置需要隐藏的输出属性

Parameters

array $hidden

属性列表

boolean $override

是否覆盖

Returns

$this

visible()

visible(array  $visible = array(), boolean  $override = false) : $this

设置需要输出的属性

Parameters

array $visible
boolean $override

是否覆盖

Returns

$this

toArray()

toArray() : array

转换当前模型对象为数组

Returns

array

toJson()

toJson(integer  $options = JSON_UNESCAPED_UNICODE) : string

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

Parameters

integer $options

json参数

Returns

string

removeRelation()

removeRelation() : $this

移除当前模型的关联属性

Returns

$this

toCollection()

toCollection(array|\think\Collection  $collection) : \think\Collection

转换当前模型数据集为数据集对象

Parameters

array|\think\Collection $collection

数据集

Returns

\think\Collection

together()

together(mixed  $relation) : $this

关联数据一起更新

Parameters

mixed $relation

关联

Returns

$this

getPk()

getPk(string  $name = '') : mixed

获取模型对象的主键

Parameters

string $name

模型名

Returns

mixed

save()

save(array  $data = array(), array  $where = array(), string  $sequence = null) : integer|false

保存当前数据对象

Parameters

array $data

数据

array $where

更新条件

string $sequence

自增序列名

Returns

integer|false

getChangedData()

getChangedData() : array

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

Returns

array

setInc()

setInc(string  $field, integer  $step = 1, integer  $lazyTime) : integer|true

字段值(延迟)增长

Parameters

string $field

字段名

integer $step

增长值

integer $lazyTime

延时时间(s)

Throws

\think\Exception

Returns

integer|true

setDec()

setDec(string  $field, integer  $step = 1, integer  $lazyTime) : integer|true

字段值(延迟)增长

Parameters

string $field

字段名

integer $step

增长值

integer $lazyTime

延时时间(s)

Throws

\think\Exception

Returns

integer|true

saveAll()

saveAll(array  $dataSet, boolean  $replace = true) : array|false

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

Parameters

array $dataSet

数据

boolean $replace

是否自动识别更新和写入

Throws

\Exception

Returns

array|false

allowField()

allowField(string|array  $field) : $this

设置允许写入的字段

Parameters

string|array $field

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

Returns

$this

except()

except(string|array  $field) : $this

设置排除写入的字段

Parameters

string|array $field

排除允许写入的字段

Returns

$this

readonly()

readonly(mixed  $field) : $this

设置只读字段

Parameters

mixed $field

只读字段

Returns

$this

isUpdate()

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

是否为更新数据

Parameters

boolean $update
mixed $where

Returns

$this

delete()

delete() : integer

删除当前的记录

Returns

integer

auto()

auto(array  $fields) : $this

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

Parameters

array $fields

需要自动完成的字段

Returns

$this

validate()

validate(array|string|boolean  $rule = true, array  $msg = array(), boolean  $batch = false) : $this

设置字段验证

Parameters

array|string|boolean $rule

验证规则 true表示自动读取验证器类

array $msg

提示信息

boolean $batch

批量验证

Returns

$this

validateFailException()

validateFailException(boolean  $fail = true) : $this

设置验证失败后是否抛出异常

Parameters

boolean $fail

是否抛出异常

Returns

$this

getError()

getError() : string|array

返回模型的错误信息

Returns

string|array

event()

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

注册回调方法

Parameters

string $event

事件名

callable $callback

回调方法

boolean $override

是否覆盖

create()

create(array  $data = array(), array|true  $field = null) : $this

写入数据

Parameters

array $data

数据数组

array|true $field

允许字段

Returns

$this

update()

update(array  $data = array(), array  $where = array(), array|true  $field = null) : $this

更新数据

Parameters

array $data

数据数组

array $where

更新条件

array|true $field

允许字段

Returns

$this

get()

get(mixed  $data, array|string  $with = array(), boolean  $cache = false) : static|null

查找单条记录

Parameters

mixed $data

主键值或者查询条件(闭包)

array|string $with

关联预查询

boolean $cache

是否缓存

Throws

\think\exception\DbException

Returns

static|null

all()

all(mixed  $data = null, array|string  $with = array(), boolean  $cache = false) : array<mixed,static>|false

查找所有记录

Parameters

mixed $data

主键列表或者查询条件(闭包)

array|string $with

关联预查询

boolean $cache

是否缓存

Throws

\think\exception\DbException

Returns

array<mixed,static>|false

destroy()

destroy(mixed  $data) : integer

删除记录

Parameters

mixed $data

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

Returns

integer —

成功删除的记录数

useGlobalScope()

useGlobalScope(boolean  $use) : \think\db\Query

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

Parameters

boolean $use

是否启用全局查询范围

Returns

\think\db\Query

has()

has(string  $relation, mixed  $operator = '>=', integer  $count = 1, string  $id = '*') : \think\model\Relation|\think\db\Query

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

Parameters

string $relation

关联方法名

mixed $operator

比较操作符

integer $count

个数

string $id

关联表的统计字段

Returns

\think\model\Relation|\think\db\Query

hasWhere()

hasWhere(string  $relation, mixed  $where = array(), mixed  $fields = null) : \think\model\Relation|\think\db\Query

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

Parameters

string $relation

关联方法名

mixed $where

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

mixed $fields

字段

Returns

\think\model\Relation|\think\db\Query

relationQuery()

relationQuery(string|array  $relations) : $this

查询当前模型的关联数据

Parameters

string|array $relations

关联名

Returns

$this

eagerlyResultSet()

eagerlyResultSet(array  $resultSet, string  $relation) : array

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

Parameters

array $resultSet

数据集

string $relation

关联名

Returns

array

eagerlyResult()

eagerlyResult(\think\Model  $result, string  $relation) : \think\Model

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

Parameters

\think\Model $result

数据对象

string $relation

关联名

Returns

\think\Model

relationCount()

relationCount(\think\Model  $result, string|array  $relation) : void

关联统计

Parameters

\think\Model $result

数据对象

string|array $relation

关联名

hasOne()

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

HAS ONE 关联定义

Parameters

string $model

模型名

string $foreignKey

关联外键

string $localKey

当前模型主键

array $alias

别名定义(已经废弃)

string $joinType

JOIN类型

Returns

\think\model\relation\HasOne

belongsTo()

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

BELONGS TO 关联定义

Parameters

string $model

模型名

string $foreignKey

关联外键

string $localKey

关联主键

array $alias

别名定义(已经废弃)

string $joinType

JOIN类型

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

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

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

morphTo()

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

MORPH TO 关联定义

Parameters

string|array $morph

多态字段信息

array $alias

多态别名定义

Returns

\think\model\relation\MorphTo

__call()

__call(  $method,   $args) 

Parameters

$method
$args

__callStatic()

__callStatic(  $method,   $args) 

Parameters

$method
$args

__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) : boolean

检测数据对象的值

Parameters

string $name

名称

Returns

boolean

__unset()

__unset(string  $name) : void

销毁数据对象的值

Parameters

string $name

名称

__toString()

__toString() 

jsonSerialize()

jsonSerialize() 

offsetSet()

offsetSet(  $name,   $value) 

Parameters

$name
$value

offsetExists()

offsetExists(  $name) 

Parameters

$name

offsetUnset()

offsetUnset(  $name) 

Parameters

$name

offsetGet()

offsetGet(  $name) 

Parameters

$name

__wakeup()

__wakeup() 

解序列化后处理

getFlagList()

getFlagList() 

getCustomList()

getCustomList() 

getStatusList()

getStatusList() 

getStateList()

getStateList() 

getFlagTextAttr()

getFlagTextAttr(  $value,   $data) 

Parameters

$value
$data

getCustomTextAttr()

getCustomTextAttr(  $value,   $data) 

Parameters

$value
$data

getRefreshtimeTextAttr()

getRefreshtimeTextAttr(  $value,   $data) 

Parameters

$value
$data

getStatusTextAttr()

getStatusTextAttr(  $value,   $data) 

Parameters

$value
$data

getStateTextAttr()

getStateTextAttr(  $value,   $data) 

Parameters

$value
$data

buildQuery()

buildQuery() : \think\db\Query

创建模型的查询对象

Returns

\think\db\Query

initialize()

initialize() : void

初始化模型

init()

init() : void

初始化处理

autoWriteTimestamp()

autoWriteTimestamp(string  $name) : mixed

自动写入时间戳

Parameters

string $name

时间戳字段

Returns

mixed

formatDateTime()

formatDateTime(mixed  $time, mixed  $format, boolean  $timestamp = false) : mixed

时间日期字段格式化处理

Parameters

mixed $time

时间日期表达式

mixed $format

日期格式

boolean $timestamp

是否进行时间戳转换

Returns

mixed

writeTransform()

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

数据写入 类型转换

Parameters

mixed $value

string|array $type

要转换的类型

Returns

mixed

getRelationData()

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

获取关联模型数据

Parameters

\think\model\Relation $modelRelation

模型关联对象

Throws

\BadMethodCallException

Returns

mixed

readTransform()

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

数据读取 类型转换

Parameters

mixed $value

string|array $type

要转换的类型

Returns

mixed

parseAttr()

parseAttr(array  $attrs, array  $result, boolean  $visible = true) : array

解析隐藏及显示属性

Parameters

array $attrs

属性

array $result

结果集

boolean $visible

Returns

array

subToArray()

subToArray(\think\Model|\think\model\Collection  $model,   $visible,   $hidden,   $key) : array

转换子模型对象

Parameters

\think\Model|\think\model\Collection $model
$visible
$hidden
$key

Returns

array

isPk()

isPk(string  $key) : boolean

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

Parameters

string $key

名称

Returns

boolean

checkAllowField()

checkAllowField(  $auto = array()) 

Parameters

$auto

autoRelationUpdate()

autoRelationUpdate(  $relation) 

Parameters

$relation

getWhere()

getWhere() : mixed

获取更新条件

Returns

mixed

autoCompleteData()

autoCompleteData(array  $auto = array()) : void

数据自动完成

Parameters

array $auto

要自动更新的字段列表

validateData()

validateData(array  $data, mixed  $rule = null, boolean  $batch = null) : boolean

自动验证数据

Parameters

array $data

验证数据

mixed $rule

验证规则

boolean $batch

批量验证

Returns

boolean

trigger()

trigger(string  $event, mixed  $params) : boolean

触发事件

Parameters

string $event

事件名

mixed $params

传入参数(引用)

Returns

boolean

parseQuery()

parseQuery(mixed  $data, string  $with, boolean  $cache) : \think\db\Query

分析查询表达式

Parameters

mixed $data

主键列表或者查询条件(闭包)

string $with

关联预查询

boolean $cache

是否缓存

Returns

\think\db\Query

parseModel()

parseModel(string  $model) : string

解析模型的完整命名空间

Parameters

string $model

模型名(或者完整类名)

Returns

string

getForeignKey()

getForeignKey(string  $name) : string

获取模型的默认外键名

Parameters

string $name

模型名

Returns

string

beforeInsert()

beforeInsert(  $callback, boolean  $override = false) 

模型事件快捷方法

Parameters

$callback
boolean $override

afterInsert()

afterInsert(  $callback,   $override = false) 

Parameters

$callback
$override

beforeUpdate()

beforeUpdate(  $callback,   $override = false) 

Parameters

$callback
$override

afterUpdate()

afterUpdate(  $callback,   $override = false) 

Parameters

$callback
$override

beforeWrite()

beforeWrite(  $callback,   $override = false) 

Parameters

$callback
$override

afterWrite()

afterWrite(  $callback,   $override = false) 

Parameters

$callback
$override

beforeDelete()

beforeDelete(  $callback,   $override = false) 

Parameters

$callback
$override

afterDelete()

afterDelete(  $callback,   $override = false) 

Parameters

$callback
$override

setFlagAttr()

setFlagAttr(  $value) 

Parameters

$value

setCustomAttr()

setCustomAttr(  $value) 

Parameters

$value

setRefreshtimeAttr()

setRefreshtimeAttr(  $value) 

Parameters

$value