我想在Symfony 2中构建一个Entity字段类型,并将参数传递给查询构建器以获取相关对象的过滤器列表:
$formMapper
->add('article_subcategories', 'entity',
array(
'label' => 'Podkategorie',
'multiple' => true,
'expanded' => true,
'read_only' => true,
'class' => 'FachowoArticleBundle:ArticleSubcategory',
'query_builder' => function (EntityRepository $er)
{
return $er
->createQueryBuilder('sc')
->where('sc.article_category = :id')
->orderBy('sc.name', 'ASC')
->setParameter('id', $id);
}
));
如何在formMapper中将$id传递给this函数?