Reputation: 617
I've installed SonataAdminBundle
and created custom CRUD controller for one entity. I want to perform some action after entity updated. How can I achieve this using CRUD controller's? I've noticed, that Admin*
classes have preUpdate
and postUpdate
methods for such purpose, I could use them, but I guess, that logic should be placed in controllers.
The easiest way I see it's rewriting editAction
(override this method in my controller, copy/paste code from base CRUDController
and add calling own postUpdate
), but copy/paste it's bad:) Maybe I missed some way?
Upvotes: 0
Views: 214
Reputation: 64486
If you review code written in sonata admin's editAction()
in CRUDController
you can see its calling admin's update()
method.
$object = $this->admin->update($object);
you can review update()
method in sonata base admin class before calling model manager to persist object it has a preUpdate()
call and same case for postUpdate()
after calling model manager.
That means the one you are trying to implement pre
or post
actions for your entity you have to write your own logic but the question is why you want to redo or rewrite any available action ? you can use already provided pre
or post
hooks.
Upvotes: 1