I have a entity
Product:
name # string
country # entity
categories #entity many-many
I have a form for that entity
ProductType: name categories
now i need filter categories by country but i dont wanna show a country parameter when i build the form I do
//...
$entity = new Entity\Product();
$entity->setCountry($this->getUser()->getProfile()->getCountry());
$form = $this->createForm(new Form\ProductType(), $entity);
return array('form' => $form->createView());
i want filter the categories by country in the ProductType class, how can achieve this?.
How i can pass $country value to query builder?
//...
->add('categories', 'entity', array(
'class' => 'MyBundle:Category',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBulder('c');
}
)