我在使用嵌入集合表单时遇到问题,因为我想过滤给定集合上显示的数据。IE
<?php
Class Parent
{
... some attributes ...
/**
* @ORM\OneToMany(targetEntity="Child", mappedBy="parent", cascade={"all"})
*/
private $children;
... some setters & getters ...
}
Class Child
{
private $attribute1;
private $attribute2;
/**
* @ORM\ManyToOne(targetEntity="Parent", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*/
private $parent;
... some setters & getters ...
}
然后我使用以下方法构建表单:
class ParentChildType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('children', 'collection', array(
'type' => ChildrenType(),
'allow_add' => true,
));
}
}
...
On controller:
$parent = $this->getDoctrine()->getEntityManager()->getRepository('AcmeBundle:Parent')->find( $id );
$forms = $this->createForm( new ParentChildType(), $parent)->createView();
and then..
return array('forms' => $forms->crateView());
我的问题是当我想按模型类和/或模型类过滤集合$attribute1
时。$attribute2
Child
有一种方法可以按此集合表单的条件进行过滤吗?