在 EasyAdmin EntityCrudController 的 AssociationField 上使用自动完成方法时,是否可以使用关联实体的属性作为选择标签,而不是关联的实体 ID?
例子:
我有 3 个具有以下属性的实体:
User
name
Certification
name
UserCertification
User
Certification
我的 UserCertificationCrudController 中有以下内容:
public function configureFields(string $pageName): iterable
{
return [
AssociationField::new('user')
->autocomplete(),
AssociationField::new('memberCertification')
->autocomplete(),
'lastRenewed',
'expiration',
];
}
创建新的 UserCertification
时请参见以下屏幕截图:
The autocomplete value is a reference to the respective Entity ID .我们将如何替换 User#
使用用户的名称属性?
我已经尝试过但没有成功的事情:
- 使用 ChoiceField 并向
ChoiceField->setFormTypeOptions()
提供“class”和“choice_label”方法,以及UserRepository->FindAll()
的结果到ChoiceField->setChoices()
方法 - 向
AssociationField->setFormTypeOptions()
提供“class”和“choice_label”方法
最佳答案
您是否尝试制作实体的 __toString()
方法?
关于symfony - 在 EasyAdmin 3.x 中使用 autocomplete() 时如何设置 AssociationField 选择标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62650128/