2014-09-25 75 views
2

我正在開發symfony2項目,並且我得到了這個異常。任何人有什麼想法造成它? 未找到帶'Gmjob \ ExamBundle \ Entity \ Examination object not found'消息的異常'Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException'。在/數據/阿帕奇/ WWW/emploipublic-SF /供應商/ SENSIO /框架-額外包/ Sensio公司/包/ FrameworkExtraBundle /請求/ ParamConverter/DoctrineParamConverter.php:55 \ nStackSymfony Component HttpKernel Exception NotFoundHttpException:找不到對象

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月16日16:56:03] [錯誤] [客戶端217.89.107.38] PHP致命錯誤:未收集異常'Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException'帶消息'Gmjob \ ExamBundle \ Entity \ Examination object not found。'在/data/apache/www/emploipublic-sf/vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/DoctrineParamConverter.php:55\nStack跡:\ 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-> (Object(Symfony \ Component \ HttpFoundation \ Request),Object(Sensio \ Bundle \ FrameworkExcelBundle \ 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 /請求/ ParamConverter/DoctrineParamConverter.php on line 55

+1

我會認爲這是因爲你的'$ object'爲空,'$ configuration-> isOptional();'方法返回false。 – Ohgodwhy 2014-09-25 06:29:14

回答

2

您的問題不在於DoctrineParamConverter,它在您的控制器中。

參數轉換器是轉換參數(好吧,我知道,名稱告訴它,但...)的組件。 當你寫:

public function myAction(Request $request) 

設置了一個param轉換器會給你Request對象。

當你寫:

public function myAction(MyEntityClass $object) 

然後DoctrineParamConverter將嘗試找到一個主義實體符合路由參數。

我建議從Symfony的文檔this article

相關問題