XF 2.0 Extending \XF\Mvc\Entity\Entity with class extensions

Aayush

Well-known member
I am creating a similar function as
Code:
toArray()
to process entity data and return an array. I don't want to repeat myself by writing the same method for different entities so I was trying to extend the
Code:
\XF\Mvc\Entity\Entity
class by using class extensions.

Is this the correct way to do it because I can't make it work. Or is there a better way to do it?
 
AFAIK there isn't a way to extend classes which are extended by other classes since they're not loaded through the XFCP when the extension runs, do you need it on every entity, or only specific entities? You could likely make a trait that adds a toArray function to the entities you need it on
 
Traits would work for this. I need it on some entities for my use. Let me know if there is a better way.

Thanks
 
Back
Top Bottom