如何从教义实体(Symfony 4)中加载表单选项?

时间:2018-11-30 18:27:59

标签: symfony oop entity formbuilder

我正在尝试从我的Doctrine实体FieldTypes加载我的formbuilder选项:

$formBuilder->add('type', EntityType::class, array(
          'attr' => array('class' => 'form-control select2'), 'label' => 'Type',
          'class' => FieldTypes::class,
        ));

但是我收到错误消息:

  

类App \ Controller \ FieldTypes不存在

1 个答案:

答案 0 :(得分:1)

您应该在课堂上放一个用途:

namespace App\Controller;

use App\Entity\FieldTypes;

class MyController
{
    // ...

    public function myAction()
    {
        // ...

        $formBuilder->add('type', EntityType::class, array(
            'attr' => array(
                'class' => 'form-control select2'
            ),
            'label' => 'Type',
            'class' => FieldTypes::class,
        ));

        // ...
    }

    // ...
}