For a project I have some objects, one method is to load the parent entity.
So I call the method like this:
$this->getDetails()->getEntity();
So the code of getEntity is:
public function getEntity()
{
if (isset($this->entity)) {
return $this->entity;
} else {
$mapper = new Crm_Mapper_Entity();
return $this->entity = $mapper->find($this->customerId);
}
}
Is it necessary to load the entity into the attribute? Because when I want to load it on another place it shouldnt be calling the mapper again.
Or is it that when it’s loaded, the object is already in memory and I don’t need to put it into the attribute?
Thanks
use singleton pattern like this: