Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 - No default option is configured for constraint

Tags:

forms

php

symfony

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.

like image 852
Hooch Avatar asked Oct 07 '13 20:10

Hooch


1 Answers

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"

like image 160
mabuza Avatar answered Oct 22 '22 23:10

mabuza