在我的 Symfony 4 項(xiàng)目中,我有一個(gè)ParametersAdmin實(shí)體,它包含與Entreprise實(shí)體的OneToOne關(guān)系。 /** * @ORM\OneToOne(targetEntity="App\Entity\Entreprise", mappedBy="parametresAdmin", cascade={"persist", "remove"}) */ private $entreprise;Entreprise實(shí)體有一個(gè)nom字段在我基于ParametresAdmin實(shí)體的表單中,我想包含entreprise.nom屬性。所以,我試過這個(gè):->add('entreprise', EntityType::class, [ 'label' => "Nom de l'entreprise", "class" => Entreprise::class, "choice_label" => "nom", "required" => false, ])我現(xiàn)在有了nom值,但它就像ChoiceType而不是TextType
1 回答

白板的微信
TA貢獻(xiàn)1883條經(jīng)驗(yàn) 獲得超3個(gè)贊
編輯您正在編輯的實(shí)體的子實(shí)體的值相當(dāng)容易。
您必須將表單的類型更改為 TextType,正如您可能已經(jīng)假設(shè)的那樣,并提供有關(guān)數(shù)據(jù)在“父”實(shí)體上的位置的表單信息,這可以通過以下選項(xiàng)完成property_path
:
->add('entreprise_nom', TextType::class, [
? ? ? 'label' => "Nom de l'entreprise",
? ? ? 'property_path' => 'entreprise.nom', // <--- this
? ? ? 'required' => false,
])
entreprise.nom
本質(zhì)上告訴表單組件它應(yīng)該首先訪問entreprise
您的實(shí)體上的屬性,然后在該值上它應(yīng)該訪問該nom
屬性(您可以在屬性訪問)。如果提交了表單并且刷新了實(shí)體管理器,它還將更改(?。?code>nom上的屬性。entreprise
- 1 回答
- 0 關(guān)注
- 111 瀏覽
添加回答
舉報(bào)
0/150
提交
取消