简体   繁体   English

Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException:找不到对象

[英]Symfony\Component\HttpKernel\Exception\NotFoundHttpException: object not found

i'm working on symfony2 project and i get this exception. 我正在研究symfony2项目,我得到了这个例外。 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.' 未捕获的异常'Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException',消息'Gmjob \\ ExaminationBundle \\ Entity \\找不到考试对象。' in /data/apache/www/emploipublic-sf/vendor/sensio/framework-extra bundle/Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/DoctrineParamConverter.php:55\\nStack 在/ 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.' [Tue Sep 09 16:56:03 2014] [error] [client 217.89.107.38] PHP致命错误:未捕获异常'Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException',消息'Gmjob \\ ExaminationBundle \\ Entity \\未找到检查对象“。 in /data/apache/www/emploipublic-sf/vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/DoctrineParamConverter.php:55\\nStack trace:\\n 在/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 #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(对象(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 #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在第55行

Your problem is not in the DoctrineParamConverter , it is in your controller. 您的问题不在DoctrineParamConverter ,而是在您的控制器中。

Param Converters are components that convert parameters (ok, I know, the name tell it but...). Param转换器是转换参数的组件(好吧,我知道,名字告诉它但是......)。 When you write : 当你写:

public function myAction(Request $request)

a param converter will give you the Request object. param转换器将为您提供Request对象。

And when you write : 当你写:

public function myAction(MyEntityClass $object)

Then the DoctrineParamConverter will try to find an Doctrine entity matching your routing parameters. 然后DoctrineParamConverter将尝试查找与您的路由参数匹配的Doctrine实体。

I recommand this article from the Symfony's documentation. 我推荐Symfony文档中的这篇文章

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Symfony\Component\HttpKernel\Exception\NotFoundHttpException - Symfony\Component\HttpKernel\Exception\NotFoundHttpException Symfony \\组件\\ HttpKernel \\异常\\ NotFoundHttpException - Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException 异常:“Symfony\Component\HttpKernel\Exception\NotFoundHttpException”,...} - exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",…} "{消息:“”,异常:“Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException”,...}" - {message: "", exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",…} 异常:“Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException”,... - exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",… Laravel 4错误Symfony \\组件\\ HttpKernel \\异常\\ NotFoundHttpException - Laravel 4 Error Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Laravel错误Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException - Laravel error Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Laravel中的Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException错误 - Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Error in Laravel Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException Laravel - Symfony\Component\HttpKernel\Exception\NotFoundHttpException Laravel Symfony \\组件\\ HttpKernel \\异常\\ NotFoundHttpException Laravel 4.1 - Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException Laravel 4.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM