我正在研究symfony2项目,我得到了这个例外。谁知道造成它的原因是什么? 未捕获的异常' Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException'消息' Gmjob \ ExaminationBundle \ Entity \找不到考试对象。'在/ 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;
}
这是抛出异常的堆栈跟踪:
[Tue Sep 09 16:56:03 2014] [error] [client 217.89.107.38] PHP致命错误:未捕获异常' Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException'消息' Gmjob \ ExaminationBundle \ Entity \找不到考试对象。'在/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第55行的/Request/ParamConverter/DoctrineParamConverter.php
答案 0 :(得分:2)
您的问题不在DoctrineParamConverter
,它在您的控制器中。
Param转换器是转换参数的组件(好吧,我知道,名字告诉它但是......)。 当你写:
public function myAction(Request $request)
param转换器会为您提供Request
对象。
当你写:
public function myAction(MyEntityClass $object)
然后DoctrineParamConverter
将尝试查找与您的路由参数匹配的Doctrine实体。
我建议从Symfony的文档中this article。