php - 自动加载器预期类 Symfony2

标签 php symfony doctrine-orm autoloader

我正在使用 symfony 2.3 框架,自动加载器声称已找到文件但没有找到类:

RuntimeException: The autoloader expected class "Sensio\Bundle\
FrameworkExtraBundle\Request\ParamConverter\DateTimeParamConverter" 
to be defined in file "/home/na/auth/vendor/sensio/framework-extra-bundle/
Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/
DateTimeParamConverter.php". The file was found but the class was not in it, 
the class name or namespace probably has a typo.

这是指的文件如下所示:

<?php

/*
 * This file is part of the Symfony framework.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use DateTime;

/**
 * Convert DateTime instances from request attribute variable.
 *
 * @author Benjamin Eberlei <kontakt@beberlei.de>
 */
class DateTimeParamConverter implements ParamConverterInterface
{
    /**
     * @{inheritdoc}
     * 
     * @throws NotFoundHttpException When invalid date given
     */
    public function apply(Request $request, ConfigurationInterface $configuration)
    {
        $param = $configuration->getName();

        if (!$request->attributes->has($param)) {
            return false;
        }

        $options = $configuration->getOptions();
        $value   = $request->attributes->get($param);

        $date = isset($options['format'])
            ? DateTime::createFromFormat($options['format'], $value)
            : new DateTime($value);

        if (!$date) {
            throw new NotFoundHttpException('Invalid date given.');
        }

        $request->attributes->set($param, $date);

        return true;
    }

    /**
     * @{inheritdoc}
     */
    public function supports(ConfigurationInterface $configuration)
    {
        if (null === $configuration->getClass()) {
            return false;
        }

        return "DateTime" === $configuration->getClass();
    }
}

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

 2028  php app/console doctrine:schema:create
 2029  php app/console doctrine:generate:entities Auth

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

最佳答案

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

关于php - 自动加载器预期类 Symfony2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17058076/

相关文章:

xml - 资源 xml 中的路由文件

php - Doctrine2 - 限制返回的关联实体

php - 将表单数据发布到另一个页面,然后再次发布

php - 将数据发布到表: all data in table shows as 1

symfony - 刷新调用不应该使旧访问 token 失效吗?

php - 学说 2 : group by field alias (Error: '...' does not point to a Class. )

mysql - 创建查询生成器 symfony 内连接

javascript - $_SERVER ['PHP_self' ] 表单中的请求无需 htmlspecialchars 即可破解

php - id 不是 auto_increment 并试图在行之间获取差异 mysql php

mysql - 将 MySQL 转换为 Doctrine 查询生成器。 IF 和 CONCAT 的问题。或者选择子查询的另一种方法