Php Symfony 3表单类型错误

Php Symfony 3表单类型错误,php,symfony,Php,Symfony,我的实体“News”包含以下字段: /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(type="string", length=100) */ protected $name; /** * @ORM\Column(type="text") */ protected $descriptio

我的实体“News”包含以下字段:

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=100)
 */
protected $name;


/**
 * @ORM\Column(type="text")
 */
protected $description;
我在控制器中生成表单:

public function createNewsAction(Request $request)
{
    $news = new News();
    $news->setName('New!');
    $news->setDescription('test');
    $form = $this->createFormBuilder($news)
        ->add('name', TextType::class)
        ->add('description', TextType::class)
        ->add('save', SubmitType::class, array('label' => 'Create Task'))
        ->getForm();
    return $this->render('frontend/createNews.html.twig', array(
        'form' => $form->createView(),
    ));
}
当我尝试调用这个方法(“createNewsAction”)时,我得到了一个错误:

Could not load type "Doctrine\DBAL\Types\TextType"

500 Internal Server Error - InvalidArgumentException

Stack Trace

in vendor\symfony\symfony\src\Symfony\Component\Form\FormRegistry.php at line 87   -
                if (class_exists($name) && in_array('Symfony\Component\Form\FormTypeInterface', class_implements($name))) {
                    $type = new $name();
                } else {
                    throw new InvalidArgumentException(sprintf('Could not load type "%s"', $name));
                }
            }

此代码有什么问题?

检查控制器顶部的
使用
语句…
您可能使用过:

use Doctrine\DBAL\Types\TextType
应该是:

use Symfony\Component\Form\Extension\Core\Type\TextType;

TextType和SubmitType需要一个use语句。检查示例,我发现了错误。在控制器中,语句“use-doctor\DBAL\Types\TextType;”必须是“use-Symfony\Component\Form\Extension\Core\Type\TextType;”