Last Updated: February 06, 2019
·
11.05K
· pleone

Symfony2 Doctrine Extensions Timestampable setup

Not so easy to find proper documentation :/ So, these are the steps i followed to enable timestampable:

1. Install StofDoctrineExtensionsBundle:

Use composer :

"require": {
...
    "stof/doctrine-extensions-bundle": "dev-master",
}  

Then activate the bundle in the kernel:
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle()

2. Follow the instruction on this page for the rest of config: https://github.com/stof/StofDoctrineExtensionsBundle/blob/master/Resources/doc/index.rst
I skipped Add the extensions to your mapping and Enable the softdeleteable filter cause i didn't need them.

3. Configure annotations on Entity:

 use Gedmo\Mapping\Annotation as Gedmo;
/**
 * @var datetime $created
 *
 * @Gedmo\Timestampable(on="create")
 * @ORM\Column(type="datetime")
 */
private $created;

You can do the same for the updated field, using on=update

More info about doctrine annotations available here http://gediminasm.org/article/timestampable-behavior-extension-for-doctrine-2

1 Response
Add your response

Thanks man for sharing this code. You are awesome

over 1 year ago ·