I was following tutorial book for Symfony2. I was doing project with forms.
Chapter 12: Forms | 150
My code:
public function newAction(Request $request)
{
$task = new Task();
$task->setTask('Find EiM group');
$task->setDueDate(new DateTime('tomorrow'));
$form = $this->createFormBuilder($task)
->add('task', 'text')
->add('dueDate', 'date')
->add('save', 'submit')
->getForm();
return $this->render('AcmeTaskBundle:Default:new.html.twig', array(
'form' => $form->createView()));
}
And I'm getting error from the topic.
No default option is configured for constraint Symfony\Component\Validator\Constraints\DateTime
What it can be? How to fix it? I followed example in book strictly.
This:
$task->setDueDate(new DateTime('tomorrow'));
should be:
$task->setDueDate(new \DateTime('tomorrow'));
Notice the forward slash before Datetime. Check your "use" statement, you probably imported and are using the class 'Symfony\Component\Validator\Constraints\DateTime"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With