Symfony2 验证器想成为 ValidatorInterface 的一个实例

Symfony2 validator wants to be an instance of ValidatorInterface

我想在 Symfony2 中创建一个表单,所以我遵循了这方面的教程 site

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(),
        ));
    }
}

在我的模板中,我想调用此表单:

{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}

但是当我调用我的模板时,出现以下错误:

Validator must be instance of Symfony\Component\Validator\Validator\ValidatorInterface or Symfony\Component\Validator\ValidatorInterface

我不知道,如何解决这个问题。

编辑

这是 Anfrage 的实体:

<?php   

namespace Project\MarkupConverterBundle\Entity;

class Anfrage {

    protected $name;
    protected $age;
    protected $email;

    public function getName()
    {
        return $this->name;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getAge()
    {
        return $this->age;
    }

    public function setAge($age)
    {
        $this->age = $age;
    }

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->$email = $email;
    }
}

编辑2

当我尝试使用没有类的表单时,我得到了同样的错误

namespace Project\Foo\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class UploadController extends Controller
{

public function indexAction(Request $request)
{
    $defaultData = array('message' => 'The message from you');

    $form = $this->createFormBuilder($defaultData)
        ->add('message', 'text')
        ->add('save', 'submit', array('label' => 'Create Task'))
        ->getForm();

    $form->handleRequest($request);

    if ($form->isValid()){
        $data = $form->getData();
    }

    return $this->render(
        'Foo:Upload:index.html.twig',
        array(
            'title' => 'Foo',
            'form' => $form->createView(),
        ));
    }
}

问题已解决:我的服务名称是 Validator。这不是一个好主意。感谢所有试图提供帮助的人。