gpt4 book ai didi

php - Symfony\组件\HttpKernel\异常\NotFoundHttpException : object not found

转载 作者:搜寻专家 更新时间:2023-10-31 21:08:59 25 4
gpt4 key购买 nike

我正在做 symfony2 项目,我遇到了这个异常。有人知道是什么原因造成的吗?未捕获异常“Symfony\Component\HttpKernel\Exception\NotFoundHttpException”,消息为“找不到 Gmjob\ExaminationBundle\Entity\Examination 对象”。在/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;
}

这里是抛出异常的堆栈跟踪:

[2014 年 9 月 9 日星期二 16:56:03] [错误] [客户端 217.89.107.38] PHP fatal error :未捕获的异常 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' 消息为 'Gmjob\ExaminationBundle\Entity\Examination找不到对象。在/data/apache/www/emploipublic-sf/vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/DoctrineParamConverter.php:55\n堆栈跟踪:\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->应用(对象(Symfony\Component\HttpFoundation\Request),对象(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(对象(Symfony\Component\HttpFoundation\Request), 对象(Sens in/data/apache/www/emploipublic-sf/vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/DoctrineParamConverter.php 第55行

最佳答案

您的问题不在 DoctrineParamConverter 中,而是在您的 Controller 中。

Param Converters 是转换参数的组件(好吧,我知道,名字告诉它但是......)。当你写的时候:

public function myAction(Request $request)

参数转换器将为您提供 Request 对象。

当你写的时候:

public function myAction(MyEntityClass $object)

然后 DoctrineParamConverter 将尝试找到与您的路由参数匹配的 Doctrine 实体。

我推荐this article来自 Symfony 的文档。

关于php - Symfony\组件\HttpKernel\异常\NotFoundHttpException : object not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26031985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com