1-33
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Symfony2 – Franz Jordán 2011<br />
The above example assumes that you've created and mapped a created property (not shown<br />
here).<br />
Now, right before the entity is first persisted, Doctrine will automatically call this method and<br />
thecreated field will be set to the current date.<br />
This can be repeated for any of the other lifecycle events, which include:<br />
preRemove<br />
postRemove<br />
prePersist<br />
postPersist<br />
preUpdate<br />
postUpdate<br />
postLoad<br />
loadClassMetadata<br />
For more information on what these lifecycle events mean and lifecycle callbacks in general, see<br />
Doctrine's Lifecycle Events documentation<br />
Lifecycle Callbacks and Event Listeners<br />
Notice that the setCreatedValue() method receives no arguments. This is always the case for<br />
lifecylce callbacks and is intentional: lifecycle callbacks should be simple methods that are<br />
concerned with internally transforming data in the entity (e.g. setting a created/updated field,<br />
generating a slug value).<br />
If you need to do some heavier lifting - like perform logging or send an email - you should<br />
register an external class as an event listener or subscriber and give it access to whatever<br />
resources you need. For more information, see Registering Event Listeners and Subscribers.<br />
Doctrine Extensions: Timestampable, Sluggable, etc.<br />
Doctrine is quite flexible, and a number of third-party extensions are available that allow you to<br />
easily perform repeated and common tasks on your entities. These include thing such<br />
as Sluggable,Timestampable, Loggable, Translatable, and Tree.<br />
For more information on how to find and use these extensions, see the cookbook article<br />
aboutusing common Doctrine extensions.<br />
Doctrine Field Types Reference<br />
Doctrine comes with a large number of field types available. Each of these maps a PHP data type<br />
to a specific column type in whatever database you're using. The following types are supported<br />
in Doctrine:<br />
Strings<br />
Numbers<br />
string (used for shorter strings)<br />
text (used for larger strings)<br />
integer<br />
100