如何使用Symfony EasyAdmin 4中的关联领域4
当我使用时:
public function configureFields(string $pageName): iterable
{
return [
AssociationField::new('XYZ')
];
}`
我收到错误 “App\Entity\XYZ 类的对象无法转换为字符串”
当我将 ->autocomplete()
添加到 AssociationField::new('XYZ')
,然后它可以工作,但在保存时显示错误 “预期参数类型为“?string”,“App\Entity\XYZ”在属性路径中给出” XYZ"。
什么使用此字段与多对一关系的正确方法是什么? ://symfony.com/doc/current/EasyAdminBundle/fields/AssociationField.html 根本没有帮助。
When I use:
public function configureFields(string $pageName): iterable
{
return [
AssociationField::new('XYZ')
];
}`
I get error "Object of class App\Entity\XYZ could not be converted to string"
When I add ->autocomplete()
to the AssociationField::new('XYZ')
, then it works, but on save it displays error "Expected argument of type "?string", "App\Entity\XYZ" given at property path "XYZ".
Whats the CORRECT way to use this field with many to one relation? Symfony Easy Admin documentation https://symfony.com/doc/current/EasyAdminBundle/fields/AssociationField.html doesn't help at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的实体
App\Entity\XYZ
将转换为关联字段中的字符串(这是标准的 symfony 实体类型)。否则无法在实体选择中设置标签。它将尝试使用 __toString 方法对其进行转换,因此您需要将其添加到您的实体中。
例如:
EasyAdmin 应该能够猜测实体类,因此您不必像简单的
EntityType
那样指定它。Your entity
App\Entity\XYZ
will be converted to a string in your association field (which is a standard symfony entity type). Otherwise there is no way to set a label in your entity select.It will try to convert it using the __toString method, so you need to add it in your entity.
For example:
EasyAdmin should be able to guess the entity class, so you don't have to specify it like you would for a simple
EntityType
.