首页›模型层›Model\Model 属性访问
Model\Model 属性访问
getAttr / setAttr / toArray 等属性读写接口
本页内容
- 方法清单
- 注意事项
方法清单
| 方法 | 签名 | 说明 |
|---|---|---|
__get / __set | ($name) / ($name,$value) | 魔术代理到 getAttributes/setAttributes |
getAttr | getAttr($name) | 读取属性(不存在抛 Exception 终止) |
getAttributes | getAttributes($name) | 同上 |
setAttr | setAttr($name,$value) | 设置属性(输入过滤器 + 变更追踪) |
setAttributes | setAttributes($name,$value) | 同上 |
setAttrs | setAttrs($attrs) | 批量设置 |
hasAttr | hasAttr($name) | 属性是否存在 |
listValuesChanged | listValuesChanged($withFilter=true) | 只列变更的属性 |
toArray | toArray($withFilter=true) | 全部属性数组(默认过输出过滤器) |
典型用法
$model = ProductModel::findByid(5);
echo $model->title; // 魔术读取(等价 getAttr)
$model->price = 1990; // 魔术写入(自动变更追踪)
$model->setAttrs(I("request")); // 批量注入提交数据
$arr = $model->toArray(); // 转数组(输出过滤:时间戳→日期等)注意事项
getAttr 对不存在的属性直接 Exception 终止;toArray(false) 关闭输出过滤器(取原始值,validata 内部即如此)。
KuoqiPHP v1.05 · 离线静态文档 · 界面基于 KuoqiUI ·
返回首页