I have function in symfony repository
public function getAllSites($criteria = null)
{
$qb = $this->createQueryBuilder('s')
->select('s')
->orderBy('s.root', 'ASC')
->addOrderBy('s.lft', 'ASC');
if($criteria !== null):
foreach ($criteria as $field => $value):
if (!$this->getClassMetadata()->hasField($field)):
continue; // Make sure we only use existing fields (avoid any injection)
endif;
$qb ->andWhere($qb->expr()->eq('s.'.$field, ':s_'.$field))
->setParameter('s_'.$field, $value);
endforeach;
endif;
return $qb->getQuery()->getResult();
}
I would like to check the type of field and then use search LIKE %word% if the field type is string (or text) and andWhere for other fields.
Do you know which function return fieldType in symfony repository?
I think you are looking for PHP's
getType()
function. See the PHP docs for more info on how to use it.