CakePHPでは以下のように仮想プロパティが設定できるが、デフォルトではエンティティを配列やJSONに変換した際に仮想プロパティは現れない。
class User extends Entity
{
protected function _getFullName()
{
return $this->_properties['first_name'] . $this->_properties['last_name'];
}
}
しかし以下のように仮想プロパティを設定すれば配列やJSONに変換した際に設定した仮想プロパティも出力してくれるようになる。
class User extends Entity
{
//省略
protected $_virtual = ['full_name'];
//省略
}
これでエンティティをtoArrayした時も仮想エンティティを含んだ配列を出力してくれる


