How can I call a initialization method for all my models in doctrine2?
Im using Doctrine2 and I have a fair amount of model Objects.
开发者_C百科All the objects inherit from a base class called BaseModel, and I need that every object call a method when its constructed. Since Doctrine doesnt call __construct, i cannot use that.
And from what I've seen, if I wanted to use the life cycle methods, I would have to modify all of my objects, they are over 50 of them...
Is there a way to define in one place a common life cycle method?
Set your BaseModel
to be a mapped superclass with the appropriate life cycle callbacks, eg
/** @MappedSuperclass @HasLifecycleCallbacks */
class BaseModel
{
/** @PostLoad */
public function doStuffOnPostLoad()
{
// do stuff
}
}
精彩评论