我尝试制作一个可供许多实体使用的动态搜索表单。一切正常,但我需要测试所有字段以检查类型和他的标准:text => LIKE,choice => EQ,choice => IN (multiple =true)...你有什么想法吗?谢谢...
public function search($Type, $search, $container)
{
$repository = $container->getDoctrine()->getRepository('prodCMDBBundle:'.$Type);
$queryBuilder = $repository->createQueryBuilder('a');
$queryBuilder->join('a.customers', 'p');
foreach ($search['docs'] as $field => $value) {
if ($repository->getClassMetadata('prodCMDBBundle:'.$Type)->hasField($field) && $value) {
// ******** ??? Check my field type ??? ******/
$queryBuilder ->andWhere($queryBuilder->expr()->eq('a.'.$field, ':a_'.$field))->setParameter('a_'.$field, $value);
}
}
return $queryBuilder->getQuery();
}