bili
bili

Reputation: 415

Symfony\Component\HttpKernel\Exception\NotFoundHttpException: object not found

i'm working on symfony2 project and i get this exception. anybody have an idea on what is causing it ? Uncaught exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' with message 'Gmjob\ExaminationBundle\Entity\Examination object not found.' in /data/apache/www/emploipublic-sf/vendor/sensio/framework-extra bundle/Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/DoctrineParamConverter.php:55\nStack

public function apply(Request $request, ConfigurationInterface $configuration)
{
    $name    = $configuration->getName();
    $class   = $configuration->getClass();
    $options = $this->getOptions($configuration);

    // find by identifier?
    if (false === $object = $this->find($class, $request, $options, $name)) {
        // find by criteria
        if (false === $object = $this->findOneBy($class, $request, $options)) {
            if ($configuration->isOptional()) {
                $object = null;
            } else {
                throw new \LogicException('Unable to guess how to get a Doctrine instance from the request information.');
            }
        }
    }

    if (null === $object && false === $configuration->isOptional()) {
        throw new NotFoundHttpException(sprintf('%s object not found.', $class)); // this is line 55
    }

    $request->attributes->set($name, $object);

    return true;
}

here is the stack trace of the exception thrown :

[Tue Sep 09 16:56:03 2014] [error] [client 217.89.107.38] PHP Fatal error: Uncaught exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' with message 'Gmjob\ExaminationBundle\Entity\Examination object not found.' in /data/apache/www/emploipublic-sf/vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/DoctrineParamConverter.php:55\nStack trace:\n

#0 /data/apache/www/emploipublic-sf/vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/ParamConverterManager.php(92): Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\DoctrineParamConverter->apply(Object(Symfony\Component\HttpFoundation\Request), Object(Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter))\n

#1 /data/apache/www/emploipublic-sf/vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/ParamConverterManager.php(48): Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterManager->applyConverter(Object(Symfony\Component\HttpFoundation\Request), Object(Sens in /data/apache/www/emploipublic-sf/vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/DoctrineParamConverter.php on line 55

Upvotes: 3

Views: 6270

Answers (1)

Yann Eugoné
Yann Eugoné

Reputation: 1361

Your problem is not in the DoctrineParamConverter, it is in your controller.

Param Converters are components that convert parameters (ok, I know, the name tell it but...). When you write :

public function myAction(Request $request)

a param converter will give you the Request object.

And when you write :

public function myAction(MyEntityClass $object)

Then the DoctrineParamConverter will try to find an Doctrine entity matching your routing parameters.

I recommand this article from the Symfony's documentation.

Upvotes: 2

Related Questions