I'm working with Symfony2 and Doctrine2 and I have a class called Domains with properties some names - strings and some dates. I use the following code to persists the information to the database:
public function createAction()
{
$date = new \DateTime();
$domain = new Domains();
$domain->setMainDomain('new domain');
$domain->setUser('new user');
$domain->setSrv('server1');
$domain->setStartDate($date->setDate(1992, 6, 3));
$domain->setDueDate($date->setDate(1998, 7, 21));
$domain->setPrevStartDate($date->setDate(1800, 9, 15));
$domain->setPrevDueDate($date->setDate(1850, 10, 25));
$domain->setNotified($date->setDate(2222, 3, 21), $date->setTime(12,01));
$em = $this->getDoctrine()->getEntityManager();
$em->persist($domain);
$em->flush();
return new Response('Added a new domain with number '.$domain->getId());
}
The problem is that all the dates has the value of the last one in the list :( In the example all of the dates become 2222-03-21. Can you please help me to fix this without creating a new DateTime object for every date which I want to persist in the datebase? Thank you very much in advance!