-1

I have a user database, and when a new user signs up, I store the name, age, address ... but there is a field in my databases named created_at which should store the time when the user is registerd. In plain php I used to do it like:

INSERT INTO users (name, created) VALUES (?, NOW())

But with symfony doctrine does everything and I don't know how to alter the entity or database to create the date using something equivallent to NOW()

hidar
  • 5,449
  • 15
  • 46
  • 70
  • 1
    You can set a default value to the field of `CURRENT_TIMESTAMP` and it will just set the value automatically. See https://stackoverflow.com/questions/5818423/set-now-as-default-value-for-datetime-datatype – Jonathan Aug 21 '18 at 21:42

1 Answers1

1

Add it into the constructor for the class:

public function __construct()
{
    $this->created = new \DateTime;
}
Chip Dean
  • 4,222
  • 3
  • 24
  • 36