小编ras*_*pin的帖子

Symfony 3表单类型错误

我有实体"新闻"与字段:

/**
 * @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;
Run Code Online (Sandbox Code Playgroud)

我在我的控制器中生成表单:

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(),
    ));
}
Run Code Online (Sandbox Code Playgroud)

当我尝试调用此方法("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) …
Run Code Online (Sandbox Code Playgroud)

php symfony

5
推荐指数
1
解决办法
5227
查看次数

标签 统计

php ×1

symfony ×1