1
我有一個簡單的形式,以主題爲功能來過濾列表:Symfony |樹枝得到現場數據時,顯示形式
$builder
->add('themes', EntityType::class, array(
'class' => 'XXBundle:Theme',
'choice_label' => 'image',
...
))
->add('save', SubmitType::class)
;
而且在樹枝我嘗試訪問所有主題做了具體的呈現,其實我想顯示圖像(與每個主題相關:theme.image)而不是主題。
我跟其他的解決方案:Symfony2 + CreateFormBuilder how to render an image in a form
但它不工作:
form.vars.value.themes/form.vars.data.themes (or form.themes.vars.value/form.themes.vars.data this is the same)
存在,但始終是空的。因爲這是一種新形式。如果我提交表單,它的工作形式.vars不再是空的。
我第一次展示表單時如何獲得主題?我跟着文檔(http://symfony.com/doc/current/reference/forms/twig_reference.html#form-variables-reference),但我找不到我想要的。
TY
試着用'form.themes.choices'(從choiceType派生) – Matteo
泰爲您解答。 「主題」是一個EntityType,你確定嗎?因爲我得到「方法」選擇「對象」Symfony \ Component \ Form \ FormView「不存在」 – Aximem
對不起,我didn.t試過。所以嘗試'form.themes.vars.choices' – Matteo