I'm fairly new to Symfony2 and setting up a form to input datetime data into a MySQL database via doctrine, but I'm getting the following error:
The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class DateTime. You can avoid this error by setting the "data_class" option to "DateTime" or by adding a view transformer that transforms an instance of class DateTime to scalar, array or an instance of \ArrayAccess.
When I try the suggested array('data_class' => 'dateTime') setting for the field but i get the following in a cached twig template:
Catchable Fatal Error: Object of class DateTime could not be converted to string in
I've tried a few things to get this to work also but nothing seems to work!
In my entity it's declared as the following:
/**
* @var \DateTime
*
* @ORM\Column(name="my_date", type="datetime", nullable=false)
* @Assert\Date()
*/
private $myDate;
and as a hidden field in my form:
$form = $this->createFormBuilder($myClass)
->add('myDate', 'hidden')
The reason for it being hidden is because the values are added via a javascript multistage form. Can anyone sine some light on what the issue could be, or how I go about solving it? Should I change my entity settings to 'strings'?
Thanks.