Skip to content

Instantly share code, notes, and snippets.

@magnusnordlander
Created September 11, 2011 23:03
Show Gist options
  • Save magnusnordlander/1210249 to your computer and use it in GitHub Desktop.
Save magnusnordlander/1210249 to your computer and use it in GitHub Desktop.
Search
/**
* Find/Show an Especie entity.
*
* @Route("/search", name="individuos_showby")
*
*/
public function searchAction()
{
if (!$this->get('request')->query->has('query'))
{
throw new NotFoundHttpException();
}
$query = $this->get('request')->query->get('query');
$pattern = '%' . str_replace(' ', '%', $query) . '%';
$qb = $this->createQueryBuilder('e')->orderBy('e.nombrecomun', 'DESC');
$qb->where($qb->expr()->orx(
$qb->expr()->like('e.nombrecomun', ':comun'),
$qb->expr()->like('e.nombrecientifico', ':cientifico')
));
$qb->setParameters(array('comun' => $pattern, 'cientifico' => $pattern));
return $qb->getQuery()->execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment