Symfony:在另一种表单类型中包含映射的Superclass表单
在Symfony 6中,我有一个映射的superclass
nactity,称为person
带有个人数据(名称,姓氏等)。
#[ORM\MappedSuperclass]
class Person
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 180)]
private $name;
#[ORM\Column(type: 'string', length: 255)]
private $surnames;
}
而且我有许多实体从该实体延伸,所有者
,client
and wistor
带有自己的属性,例如:
#[ORM\Entity()]
class Owner extends Person
{
#[ORM\OneToOne(inversedBy: 'owner', targetEntity: User::class, cascade: ['persist', 'remove'])]
private $user;
#[ORM\Column(type: 'boolean')]
private $isExternal = false;
}
我的问题是,我的问题是,我可以只创建一个人FormType一次,然后以某种方式将其嵌入onalyformType
,client> clientformtype
和visitorformtype
?
我知道我可以为person
创建一个FormType,并与所有者
或客户端
数据分开访问它,保存这些字段,然后完成所有者
或客户端
以另一种形式,但这导致了所需字段的问题,别名这不是一个优雅的解决方案。
in Symfony 6, I have a MappedSuperclass
Entity called Person
with personal data (name, surnames, etc.).
#[ORM\MappedSuperclass]
class Person
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 180)]
private $name;
#[ORM\Column(type: 'string', length: 255)]
private $surnames;
}
And I have a number of entities extending from that one, Owner
, Client
and Visitor
with their own properties, for example:
#[ORM\Entity()]
class Owner extends Person
{
#[ORM\OneToOne(inversedBy: 'owner', targetEntity: User::class, cascade: ['persist', 'remove'])]
private $user;
#[ORM\Column(type: 'boolean')]
private $isExternal = false;
}
My question is, can I create a Person FormType only once and somehow embed it inside the OwnerFormType
, ClientFormType
and VisitorFormType
?
I know I could create a FormType for Person
and access it separately from Owner
or Client
data, save those fields and then complete Owner
or Client
in another form, but that leads to problems with required fields, alias it's not an elegant solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您必须创建一个形式的人物。然后,您可以创建您的表单所有构图,访问类型等...
在子类的构建器中,您可以创建性格形式。
First you have to create a form PersonType. Then you create your forms OwnerType,VisitorType etc...
In The builder of the subclasses you can create the PersonType form.