將方法新增到 DataObject

你可以使用擴充套件機制將公共方法新增到 DataObject,例如:

class MyMemberExtension extends DataExtension
{
    public function getHashId()
    {
        return sha1($this->owner->ID);
    }
}

當應用於 Member 類時,上面的示例將通過受保護屬性 $this->owner 訪問 Member 來返回 Member ID 的 sha1 雜湊值。例如:

$member = Member::get()->byId(123);
var_dump($member->getHashId()); // string(40) "40bd001563085fc35165329ea1ff5c5ecbdbbeef"