use of $this inside the symfony2 QueryBuilder

Thursday, July 3, 2014

I have the following code.

$form = $this->createFormBuilder()
->add('distributor', 'entity', array(
'class' => 'AdminBundle:Customers',
'query_builder' => function(EntityRepository $repository) {
return $repository->createQueryBuilder('c')
->where('c.customerType =:type')
->Andwhere('c.status =:status')
->andWhere('c.district =:district')
->setparameter('status', '1')
->setparameter('type', '1')
->setparameter('district', $this->get("security.context")->getToken()->getUser()->getCustomer()->getDistrict()->getId())
'property' => 'customerName',
'empty_value' => 'Select Distributor',
'multiple' => FALSE,
'expanded' => FALSE,
'required' => TRUE,
->add('excel_file', 'file'

When I am going to use distributor element in the twig like this

{{ form_widget(form.distributor,{ 'attr': {'class': 'input-box'} }) }}

it is getting an error... Fatal error: Using $this when not in object context

How to use $this in the symfony QueryBuilder with form?

Thanks Rakhitha