开发者

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
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜