Symfony版本:4.4.5
我有一个表单类型QuestionType
,它有一个inputType
字段-与实体inputType
(manyToOne(的关系。我已将EntityType
字段类型的class
参数设置为实体InputType
:
<?php
namespace AppForm;
use AppEntityInputType;
use AppEntityQuestion;
use DoctrineORMEntityRepository;
use SymfonyBridgeDoctrineFormTypeEntityType;
use SymfonyComponentFormAbstractType;
use SymfonyComponentFormExtensionCoreTypeCheckboxType;
use SymfonyComponentFormExtensionCoreTypeTextType;
use SymfonyComponentFormFormBuilderInterface;
use SymfonyComponentOptionsResolverOptionsResolver;
class QuestionType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('question', TextType::class, [
'required' => true,
'label' => 'Frage',
])
->add('multipleAnswers', CheckboxType::class, [
'required' => false,
'label' => 'Mehrere Antworten zulassen',
])
->add('inputType', EntityType::class, [
'class' => InputType::class,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('i')
->orderBy('i.name', 'ASC');
},
'choice_label' => 'name',
])//->add('answers')
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Question::class,
]);
}
}
通过在浏览器中打开表单,我得到以下错误:
[Semantical Error] line 0, col 45 near 'name ASC': Error: Class AppEntityAnswer has no field or association named name
我不明白为什么-表单的inputType
字段配置正确。。。
检查nameSpace和类名是否正确。