SYMFONY 3-在CollectionType中使用相同的EntityType与儿童进入类型



在我的symfony 3.3.2项目中,我正在尝试将父实体用作collection type的嵌入式形式的childdepe,in collection type ins form builder:

class PieceType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('reference' , TextType::class , array(
              'required' => true,
              ))
            ->add('designation' , TextType::class, array(
              'required' => true,
            ))
            ->add('prix' , NumberType::class, array(
              'required' => true,
            ))
            ->add('quantite' , NumberType::class)
            ->add('etat' )
            ->add('equivalents' ,  CollectionType::class , array(
                  'entry_type'   => PieceType::class ,
                  'allow_add' => true,
                  'allow_delete' => true,
                  'prototype' => true,
                  'attr' => array(
                     'class' => 'pieces_form-collection',
                 ),
            ))

            ->add('caracteristiques' ,  CollectionType::class , array(
                  'entry_type'   => CaracteristiqueType::class ,
                  'allow_add' => true,
                  'allow_delete' => true,
                  'prototype' => true,
                  'attr' => array(
                     'class' => 'caract_form-collection',
                 ),
            ))
    }
}

当我将pieceType用作儿童型时,项目不起作用,我只有白页。有任何建议吗?

我通过在控制器中添加我的childtype来修复它:

public function editAction(Request $request, Piece $piece)
{
    $editForm = $this->createForm('EKAdministrationBundleFormPieceType', 
    $piece);
    $form = $editForm
            ->add('equivalents' , CollectionType::class , array(
                  'entry_type'   => PieceType::class ,
                  'allow_add' => true,
                  'allow_delete' => true,
                  'prototype' => true,
                  'attr' => array(
                     'class' => 'pieces_form-collection',
                 ),
    ));
    return $this->render('EKAdministrationBundle:Piece:edit.html.twig', 
    array('edit_form' => $form->createView(), ));
}

相关内容

  • 没有找到相关文章

最新更新