I searched a lot and can't find any in StackOverflow about my problem...
I have this structure: ( resumed )
$form = $this->createFormBuilder($vendedor)
// ...
->add('datanascimento', DateType::class, [
'label' =>'D.Nascimento',
'attr' =>['class'=>'input-sm'],
'format'=>'d-M-yyyy',
'years'=>range(1970, 2010)
])
// ...
->getForm();
And i have this configs in my Entity:
//...
/**
* @var \DateTime
*
* @ORM\Column(name="dataNascimento", type="date", nullable=true)
*/
private $datanascimento;
//...
/**
* Set datanascimento
*
* @param string $datanascimento
*
* @return CadPfPj
*/
public function setDatanascimento($datanascimento)
{
$this->datanascimento = $datanascimento;
return $this;
}
/**
* Get datanascimento
*
* @return string
*/
public function getDatanascimento()
{
return $this->datanascimento;
}
When i try insert an new register, i got this error:
Catchable Fatal Error: Object of class DateTime could not be converted to string
500 Internal Server Error - ContextErrorException
When i debug, and dump the object... I found this:
//...
-datanascimento: DateTime {#530 ▼
+"date": "1970-01-01 00:00:00.000000"
+"timezone_type": 3
+"timezone": "America/Sao_Paulo"
}
//...
My database was mySQL and the field type is datetime... How can i configure symfony to stop send an array and send just the "date"?
Thanks for the help!