仮想プロパティーの生成
アクセサーを定義することによって、現在存在しないフィールド・プロパティーへのアクセスを提供できます。 例えば、users テーブルが first_name
と last_name
列を持っていたとして、 フルネームのためのメソッドを作れるということです。
namespace App\Model\Entity;
use Cake\ORM\Entity;
class User extends Entity
{
protected function _getFullName()
{
return $this->_properties['first_name'] . ' ' .
$this->_properties['last_name'];
}
}
仮想プロパティーは、エンティティーに存在するかのようにアクセスできます。 プロパティー名は小文字と ”_” を使ってメソッド名を表記します。