I have a date time field
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime", nullable=true)
*/
private $datetime;
/**
* Set date
*
* @param \DateTime $datetime
*
*/
public function setDate($datetime)
{
$this->datetime = $datetime;
return $this->datetime ?? new \DateTime();
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate(): \DateTime
{
return $this->datetime ?? new \DateTime();
}
I this error below:
Call to a member function format() on array
Anyone know why I get this?
Edit:
Below is the code that I use to generate a form to read in the DateTime value and then collect the data from the form and create a new entity in the table:
$trainingform = new Training();
$form = $this->createFormBuilder($trainingform)
->add('Leader', TextType::class)
->add('Date', DateTimeType::class, ['label' => 'Date and Time'])
->add('topics', TextType::class, ['label' => 'Topics Being Covered'])
->getForm();
if ($form->handleRequest($request)->isValid()) {
$trainingform->setLeader($request->request->get('form')['Leader']);
$trainingform->setDate($request->request->get('form')['Date']);
$trainingform->setTopics($request->request->get('form')['topics']);
$em->persist($trainingform);
$em->flush();
}