FormType从实体关系中添加字段

问题描述 投票:0回答:1

在我的Symfony 4项目中,我有一个ParametersAdmin实体,其中包含与Entreprise实体的OneToOne关系。

    /**
     * @ORM\OneToOne(targetEntity="App\Entity\Entreprise", mappedBy="parametresAdmin", cascade={"persist", "remove"})
     */
    private $entreprise;

Entreprise实体具有nom字段

在基于[[ParametresAdmin实体的表单中,我想包含entreprise.nom属性。

所以,我尝试了这个:

->add('entreprise', EntityType::class, [ 'label' => "Nom de l'entreprise", "class" => Entreprise::class, "choice_label" => "nom", "required" => false, ])

我现在有

nom

值,但这就像ChoiceType而不是TextTypeenter image description here
php forms symfony entity field
1个回答
0
投票
编辑您正在编辑的实体的子实体的值非常容易。

您可能已经假设,您必须将表单的类型更改为TextType,并提供有关数据在“父”实体上的位置的表单信息,这可以通过property_path选项完成:

property_path

© www.soinside.com 2019 - 2024. All rights reserved.