My doctrine entity has a datetime property called updated. This should get the current time everytime (changed) values of the object are written to the DB. I know how to do this in MySql, but I’m looking for a doctrine/symfony solution.
Is there a way to
- hook into something before an INSERT/UPDATE of an instance is sent to the DB.
- update the
updatedproperty to the current time and make sure it’s written to the DB without triggering a second UPDATE statement.
You don’t need any extensions, just use Lifecycle Callbacks.
Basically, mark your entity that it has event callbacks configured with the
HasLifecycleCallbacksannotation:And then mark instance methods to be run on specific events occuring, e.g. to set
updated: