Symfony2 and Timestampable example

To add Timestampable behaviour you need to add DoctrineExtentions to your app see my previous post Symfony2 and DoctrineExtensions for information of how to do that.

You need to add the following in the top of the Entity

use Gedmo\Mapping\Annotation as Gedmo;

and then you can use it like this in your entity:

/**
 * @var datetime $updated
 *
 * @ORM\Column(name="updated", type="datetime")
 * @Gedmo\Timestampable
 */
private $updated;

Available configuration options: – on – is main option and can be create, update, change this tells when it should be updated – field – only valid if on=”change” is specified, tracks property for changes – value – only valid if on=”change” is specified, if tracked field has this value then it updates timestamp

Here is an example of setting the value on creation:

/**
 * @var datetime $created
 *
 * @ORM\Column(name="created", type="datetime")
 * @Gedmo\Timestampable(on="create")
 */
private $created;

For more info:
https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/timestampable.md

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>