Php Symfony2-没有为约束配置默认选项
我在看Symfony2的教程。 我在用表格做项目 第12章:表格| 150 我的代码:Php Symfony2-没有为约束配置默认选项,php,forms,symfony,Php,Forms,Symfony,我在看Symfony2的教程。 我在用表格做项目 第12章:表格| 150 我的代码: public function newAction(Request $request) { $task = new Task(); $task->setTask('Find EiM group'); $task->setDueDate(new DateTime('tomorrow')); $form = $this->createFormBuilde
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()));
}
我从这个话题中得到了错误
No default option is configured for constraint Symfony\Component\Validator\Constraints\DateTime
可能是什么?
如何修复它?
我严格遵循书中的例子。
我不确定,但在这份文件之后,基本用法是:
$builder->add('publishedAt', 'date', array(
'input' => 'datetime',
'widget' => 'choice',
));
或
也许您应该尝试在
“日期”
这:
应该是:
$task->setDueDate(new \DateTime('tomorrow'));
请注意Datetime之前的正斜杠。检查“use”语句,您可能已导入并正在使用类“Symfony\Component\Validator\Constraints\DateTime”“Jahnux73:我是不是遗漏了什么?您的第一个和第二个示例是相同的。在阅读文档时,我看到您必须在生成器中的“日期”之后插入选项数组。。。。我更新了第二个例子,它来自文档。。。(数组('input=>……)
$task->setDueDate(new DateTime('tomorrow'));
$task->setDueDate(new \DateTime('tomorrow'));