php – Autoloader预期类Symfony2

前端之家收集整理的这篇文章主要介绍了php – Autoloader预期类Symfony2前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用symfony 2.3框架,自动加载器声称已找到该文件,但没有类:
  1. RuntimeException: The autoloader expected class "Sensio\Bundle\
  2. FrameworkExtraBundle\Request\ParamConverter\DateTimeParamConverter"
  3. to be defined in file "/home/na/auth/vendor/sensio/framework-extra-bundle/
  4. Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/
  5. DateTimeParamConverter.PHP". The file was found but the class was not in it,the class name or namespace probably has a typo.

这个引用的文件如下所示:

  1. <?PHP
  2.  
  3. /*
  4. * This file is part of the Symfony framework.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11.  
  12. namespace Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter;
  13.  
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  17. use DateTime;
  18.  
  19. /**
  20. * Convert DateTime instances from request attribute variable.
  21. *
  22. * @author Benjamin Eberlei <kontakt@beberlei.de>
  23. */
  24. class DateTimeParamConverter implements ParamConverterInterface
  25. {
  26. /**
  27. * @{inheritdoc}
  28. *
  29. * @throws NotFoundHttpException When invalid date given
  30. */
  31. public function apply(Request $request,ConfigurationInterface $configuration)
  32. {
  33. $param = $configuration->getName();
  34.  
  35. if (!$request->attributes->has($param)) {
  36. return false;
  37. }
  38.  
  39. $options = $configuration->getOptions();
  40. $value = $request->attributes->get($param);
  41.  
  42. $date = isset($options['format'])
  43. ? DateTime::createFromFormat($options['format'],$value)
  44. : new DateTime($value);
  45.  
  46. if (!$date) {
  47. throw new NotFoundHttpException('Invalid date given.');
  48. }
  49.  
  50. $request->attributes->set($param,$date);
  51.  
  52. return true;
  53. }
  54.  
  55. /**
  56. * @{inheritdoc}
  57. */
  58. public function supports(ConfigurationInterface $configuration)
  59. {
  60. if (null === $configuration->getClass()) {
  61. return false;
  62. }
  63.  
  64. return "DateTime" === $configuration->getClass();
  65. }
  66. }

无论如何,一些可能有用的细节是我最近安装了Doctrine并运行命令……

  1. 2028 PHP app/console doctrine:schema:create
  2. 2029 PHP app/console doctrine:generate:entities Auth

在那些命令之后,symfony停止了工作.我不知道这是不是一些奇怪的错误.如果您需要更多信息,我可以发帖.谢谢你的帮助.

缺少(或短)PHP开始标记也可能导致该错误.是的,这听起来很有趣,但如果您只是按照Symfony示例并复制/粘贴全班,您可能不会注意到(因为我没有).

猜你在找的PHP相关文章