如何在 Silverstripe 中比较表中的两行?

问题描述 投票:0回答:2

鉴于此表,我如何比较两行并确定

DomainAdminID
如何更改?

enter image description here

php silverstripe
2个回答
0
投票

你可以使用

if($this->isChanged('DomainAdminID') {
  ...
  ...
}

在对象上的

onBeforeWrite()
函数中检测 id 是否已更改。

如果您想知道

DomainAdminID
的新值和旧值,请使用 getChangedFields()


0
投票

DataObjects 在系统中的位置以及 ID 1 和 2,您可以读取两个 DataObjects,然后比较原始数据的数组...

array_diff(MyObject::get()->ByID(1)->toMap(),MyObject::get()->ByID(2)->toMap());

http://api.silverstripe.org/3.2/class-DataObject.html#_toMap http://php.net/manual/en/function.array-diff.php

© www.soinside.com 2019 - 2024. All rights reserved.