我尝试制作一个动态搜索表单,可供许多实体使用。一切正常但我需要测试所有字段以检查类型和他的标准: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();
}