Why Symfony2 dont catch exceptions

前端 未结 2 828
孤城傲影
孤城傲影 2021-01-20 17:45

i have a repository

class TurnoRepository extends EntityRepository
{
    public function findTurnoActivo()
    {
        $q = $this
            ->createQu         


        
相关标签:
2条回答
  • 2021-01-20 18:01

    Symfony2 code is namespaced so you have to add the correct namespace for the class NoResultException, try using:

    catch (\Doctrine\ORM\NoResultException $e)
    

    Note the backslash in front of the Doctrine namespace or import the NoResultException class by using use.

    0 讨论(0)
  • 2021-01-20 18:06

    You can use $q->getOneOrNullResult(); if you don't want to catch NoResultException in the controller.

    0 讨论(0)
提交回复
热议问题