调试Model类append方法的追加顺序

This commit is contained in:
thinkphp
2016-07-09 22:16:26 +08:00
parent 3e09d80cde
commit ea1b88af50

View File

@@ -478,11 +478,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
public function toArray($allow = [])
{
$item = [];
if (!empty($this->append)) {
foreach ($this->append as $name) {
$item[$name] = $this->getAttr($name);
}
}
if (empty($allow)) {
$allow = array_keys($this->data);
}
@@ -508,6 +503,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$item[$key] = $this->getAttr($key);
}
}
// 追加属性(必须定义获取器)
if (!empty($this->append)) {
foreach ($this->append as $name) {
$item[$name] = $this->getAttr($name);
}
}
return !empty($item) ? $item : [];
}