我想在Symfony2中创建一个表单,所以我按照本网站上的教程进行操作
namespace Project\Foo\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Project\Foo\Entity\Anfrage;
use Symfony\Component\HttpFoundation\Request;
class UploadController extends Controller
{
public function indexAction(Request $request)
{
$anfrage = new Anfrage();
$anfrage->setName('Güntaa');
$anfrage->setAge(5);
$anfrage->setEmail('foo@foo.de');
$form = $this->createFormBuilder($anfrage)
->add('save', 'submit', array('label' => 'Create Task'))
->getForm();
return $this->render(
'Foo:Upload:index.html.twig',
array(
'title' => 'Foo',
'form' => $form->createView(),
));
}
}
Run Code Online (Sandbox Code Playgroud)
在我的模板中,我想调用此表单:
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
Run Code Online (Sandbox Code Playgroud)
但是当我调用我的模板时,我收到以下错误:
Validator必须是Symfony\Component\Validator\Validator\ValidatorInterface或Symfony\Component\Validator\ValidatorInterface的实例
我不知道,如何解决这个问题.
这是Anfrage实体:
<?php
namespace Project\MarkupConverterBundle\Entity;
class Anfrage {
protected $name;
protected $age;
protected $email; …Run Code Online (Sandbox Code Playgroud)