【发布时间】:2013-06-13 21:35:52
【问题描述】:
我有一个实体
Product:
name # string
country # entity
categories #entity many-many
我有那个实体的表格
产品类型: 姓名 类别
现在我需要按国家/地区过滤类别,但我不想在构建表单时显示国家/地区参数
//...
$entity = new Entity\Product();
$entity->setCountry($this->getUser()->getProfile()->getCountry());
$form = $this->createForm(new Form\ProductType(), $entity);
return array('form' => $form->createView());
我想在 ProductType 类中按国家/地区过滤类别,如何实现?
如何将 $country 值传递给查询构建器?
//...
->add('categories', 'entity', array(
'class' => 'MyBundle:Category',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBulder('c');
}
)
【问题讨论】:
-
我已经更新了我的答案。
标签: php forms symfony symfony-forms