working with doctrine and mongodb, I would like to set a datetime to a default value (new Datetime()) only when the record is create and only if no value is passed? Can I do this with annotations?
thanks
working with doctrine and mongodb, I would like to set a datetime to a default value (new Datetime()) only when the record is create and only if no value is passed? Can I do this with annotations?
thanks
No, you would do this in the __construct()
method
of the mapped Entity class. This way every time you call
new EntityClass()
it will be set. Long before any doctrine persistence kicks in.
Just:
public function __construct() {
$this->dateProperty = new \DateTime()
}