PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Jeremy Cook's Blog: Normalising DateTimes with Doctrine Events

Note: This article was originally published at PHPDeveloper on 28 June 2012.
PHPDeveloper

Jeremy Cook has written up a new post showing you a method for normalizing the date and time information in your application (DateTime) with the help of Doctrine's own event listeners.

The solution we hit on was to leverage Doctrine's system of event listeners to help us do the work. Doctrine allows you to register listeners with the entity manager that are called whenever certain events occur. We created an event listener that is triggered on the onFlush event.

Code is included for the event listener they created - a simple "onFlush" event that grabs the current entities from the manager, sets the date/time property to allow it to be changed (via Reflection) and updating it with the new cleaned format.