Reputation: 14381
I'm trying to create a form that will allow users to edit data. I need to read a value from the a table and pre-populate the form with that data.
In the code below I'm trying to set a value of 2007-02-20 16:48:00
in the form.
What I tried:
$form = $app['form.factory']->createBuilder( 'form' )
->add('start', 'datetime', array(
'data' => '2007-02-20 16:48:00')
)
->add('end', 'datetime')
->getForm();
What I got:
UnexpectedTypeException: Expected argument of type "\DateTime", "string" given
Thanks
Upvotes: 0
Views: 2095
Reputation: 7277
Symfony wants a DateTime object, so try:
$form = $app['form.factory']->createBuilder( 'form' )
->add('start', 'datetime', array(
'data' => new \DateTime('2007-02-20 16:48:00'))
)
->add('end', 'datetime')
->getForm();
Upvotes: 1