フォームの選択肢 (ラジオ ボタン) を特別な方法で表示したい。
簡単な説明:
名前 (_toString) と値 (id) だけでなく、選択ウィジェットでエンティティから多くのプロパティを表示する必要があります。
拡張説明:
エンティティは正常に機能し、問題はありません。
Album EntityとOneToOne 関係にあるSalonWeb Entityがあります。また、Album エンティティはFoto エンティティとOneToMany 関係を持ち、$fotos ArrayCollection と、$foto_id をリンクする $foto_principal プロパティを含みます。
したがって、適切な教義クエリを使用すると、次のようなものにアクセスできます。
$salon_web->getAlbum()->getFotoPrincipal();
または、小枝で:
salonWeb.album.fotoPrincipal
今まではすべて正しいです。
この写真(英語の写真)をフォーム選択ラベルとして表示したいので、このコードを実行しました(動作しています)
フォームビルダーで:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('salones', 'entity', array(
'class' => 'CommonBundle:SalonWeb',
'required' => true,
'expanded' => true,
'query_builder' => function(EntityRepository $er)
{
return $er->getQueryBuilderVisiblesContacto();
},
'property' => 'album.foto_principal'
))
// More code...
}
...そして TWIG テンプレートでは:
<div>
{{ form_errors(formulario.salones) }}
{{ form_label(formulario.salones) }}
{% for childSalon in formulario.salones %}
<label><img src="/uploads/galeria/{{ childSalon.vars.label }}" alt="" />{{ form_widget(childSalon) }}</label>
{% endfor %}
</div>
{{ form_widget(formulario) }}
ここまではすべて正常に動作しています。しかし、問題は、フォームの選択で1 つのプロパティしか表示できないことです(この場合は、SalonWeb エンティティの album.foto_principal プロパティです)。
次のようなものを示したいと思います。
<div>
{{ form_errors(formulario.salones) }}
{{ form_label(formulario.salones) }}
{% for childSalon in formulario.salones %}
<label><img src="/uploads/galeria/{{ childSalon.whatever.name }}" alt="" />{{ childSalon.whatever.address ~ ' ' ~ childSalon.whatever.anotherSalonWebProperty }}
<div>{{ childSalon.whatever.theLastProperty }}</div>
{{ form_widget(childSalon) }}</label>
{% endfor %}
</div>
{{ form_widget(formulario) }}