i have a repository
class TurnoRepository extends EntityRepository
{
public function findTurnoActivo()
{
$q = $this
->createQueryBuilder('t')
->where('t.activo = :activo')
->setParameter('activo', true)
->getQuery();
return $q->getSingleResult();
}
}
this method throw a NoResultException but if i try to catch in my controller
private function obtenerTurno()
{
$em = $this->getDoctrine()->getEntityManager();
$turno = null;
try {
$turnoActivo = $em->getRepository('MyBundle:Turno')->findTurnoActivo();
} catch (NoResultException $e) {
return false;
}
return $turno;
}
always i get 500 Internal Server Error on my page
Symfony2 code is namespaced so you have to add the correct namespace for the class
NoResultException, try using:Note the backslash in front of the Doctrine namespace or import the
NoResultExceptionclass by usinguse.