I found the Gidmo extension which eg provides a timestamp function for creation and update of objects.
Thats what I (and oddly enough nobody else from the Zend guys) need!
I tried including the namespace via use
like it is shown here. But no success. The Doctrine validation returns valid and no errors elsewhere but when creating a new object, the created_at
attribute is empty.
I also tried this approach but same result.
Any ideas what I'm doing wrong?
composer.json:
"require": {
...
"gedmo/doctrine-extensions": "dev-master"
Entity.php:
use Gedmo\Mapping\Annotation as Gedmo;
...
class Entity {
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
* @Form\Attributes({"type":"timestamp"})
* @Form\Options({"label":"Created at"})
* @Form\Exclude()
*
*/
protected $created_at;
}
I don't know if you really need an extension for achieving the functionality you're seeking,have a look over the @Version annotation discussed within this section: Optimistic Locking of the Doctrine Documentation.
[EDIT] The @Version is available (as well as all Doctrine ORM mapping annotations) under the namespace Doctrine\ORM\Mapping
Usage for a timestamp field : @Version @ORM\Column(type="datetime")
Usage for an integer field : @Version @Column(type="integer")
Version numbers (not timestamps) should however be preferred as they can not potentially conflict in a highly concurrent environment, unlike timestamps where this is a possibility, depending on the resolution of the timestamp on the particular database platform. (source: Doctrine Documentation)