Ok I found the solution:
The prePersist
option is what I'm doing.
Make sure you define in the annotations
<?php
/** @Entity
* @HasLifecycleCallbacks
*/
class User
and here is the function example they offer
/**
* @PrePersist
*/
public function doStuffOnPrePersist()
{
$this->createdAt = date('Y-m-d H:i:s');
}
And if you're using ORM like I am
<?php
/** @ORMEntity
* @ORMHasLifecycleCallbacks
*/
class User
and here is the function example they offer
/**
* @ORMPrePersist
*/
public function doStuffOnPrePersist()
{
$this->createdAt = date('Y-m-d H:i:s');
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…