Symfony表单集合不会删除元素

时间:2014-02-20 21:23:11

标签: php forms symfony

表格类型

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
            ......
            ->add('menores', 'collection', array(
                'type' => new CotizacionMenorType(),
                'allow_add' => true,
                'allow_delete' => true,
                'by_reference' => false,
                'required'  => false
            ))
            ......
    ;
}

控制器

public function editarAction(Cotizacion $cotizacion, Request $request)
{

    $pageData['accion'] = 'Editar';

    $objForm = $this->createForm(new EditarCotizacionType(), $cotizacion);

    $objForm->handleRequest($request);

    if ($objForm->isValid()) {
        echo '<pre>';
        echo \Doctrine\Common\Util\Debug::dump($cotizacion->getMenores());
        die('</pre>');
        .............
    }
    .......
}

当我渲染表单并从DOM 1元素中删除表单时,我提交表单和仍然在coleccion中的元素。当我打印de $cotizacion->getMenores()时,删除的元素仍在那里

由于

2 个答案:

答案 0 :(得分:2)

在你的关系注释中,确保你设置了orphanRemoval。

@ORM\OneToMany(targetEntity="Image", cascade={"persist"}, orphanRemoval=true)

答案 1 :(得分:0)

此错误是由版本2.3.10 https://github.com/symfony/symfony/issues/10256中的错误引起的,感谢A6 Software的帮助。