EntityTypeから値を取得できません。私は最後のバージョン3.3.6を持っています。EntityTypeから値を取得するSymfony
class BuildType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array
$options)
{
$builder
->add('title', TextType::class)
->add('save', SubmitType::class, array('label' => 'Create Post'))
->add('team', CollectionType::class, array(
// each entry in the array will be an "email" field
'entry_type' => TeamType::class,
// these options are passed to each "email" type
'entry_options' => array(
'attr' => array('class' => 'form-control'),
),
'label' => false,
'allow_add' => true,
'prototype' => true,
'mapped' => false
));
}
}
class TeamType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array
$options)
{
$builder
->add('name', EntityType::class, array(
'placeholder' => 'Choice a champ',
'required' => true,
'class' => 'AppBundle:Champions',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('c')
->orderBy('c.name', 'ASC');
},
'choice_label' => 'name',
'choice_value' => 'id',
'attr' => array('class' => 'dropdown'),
));
}
私はすべてを試してみましたが、私はTeamTypeの '名前' の値を取ることができません。投稿フォームの後、私は行う
foreach ($form["team"]->getData() as $value) {
'name' => $value['name']
しかし値は空です。私はダンプ要求を試して、値がそこにある場合。他の値は取得してデータベースに保存することができます。 EntityTypeのみができません。 誰か知っているのですか?
?スニペットを提供できますか? –
奇妙なことに、 'TeamType'には1つのフィールドだけが含まれている場合、なぜそれを別のフォームタイプに抽出しましたか? –