$repository = $this->getDoctrine()->getRepository('ParabolaEntityBundle:ProjectAllocation');
$query = $repository->createQueryBuilder('p')
->where('p.startDate < :sdate and p.employee = :emp and p.endDate > :edate')
->setParameter('sdate', date('Y-m-d', time()))
->setParameter('edate', date('Y-m-d', time()))
->setParameter('emp', $employee->getId())
->getQuery();
$projectAllocate = $query->getResult();
how can i use above code in FormType class.I am using this query to generate array for the choice type in form builder.
I think you should use
entitytype instead which has aquery_builderoption.This link:
http://symfony.com/doc/current/reference/forms/types/entity.html
Describes how to do it.
If, for some reason you really don’t want to use
entitytype, you could always retrieve data within controller and pass it viaFormTypeconstructor, which is a little bit quick ‘n’ dirty but should work just fine…Controller:
FormType: