找不到Doctrine Repository类

时间:2017-01-07 11:07:44

标签: symfony doctrine-orm

从Symfony2 + Doctrine获取奇怪的错误。班级在其中,没有错别字。

 Uncaught PHP Exception Doctrine\Common\Persistence\Mapping\MappingException: "The class 'AppBundle\Repository\ORM\ImageRepository' was not found in the chain configured namespaces AppBundle\Entity" at /Users/macbook/Projects/stfalcon_test/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php line 37 {"exception":"[object] (Doctrine\\Common\\Persistence\\Mapping\\MappingException(code: 0): The class 'AppBundle\\Repository\\ORM\\ImageRepository' was not found in the chain configured namespaces AppBundle\\Entity at /Users/macbook/Projects/stfalcon_test/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:37)"} []

实体类的开头:

/**
 * Image
 *
 * @ORM\Table(name="image")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\ORM\ImageRepository")
 * @Vich\Uploadable
 */
class Image
{

Repository类的开头:

namespace AppBundle\Repository\ORM;

use AppBundle\Repository\Interfaces\ImageRepositoryInterface;
use Doctrine\ORM\EntityRepository;

/**
 * ImageRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class ImageRepository extends EntityRepository implements ImageRepositoryInterface
{

1 个答案:

答案 0 :(得分:1)

解决方案很简单。错误发生在服务类中,因为我想将存储库注入到管理器中。有我的服务文件:

services:
    app.repository.orm.image_repository:
        class: Doctrine\ORM\EntityRepository
        factory: ['@doctrine.orm.default_entity_manager', getRepository]
        arguments:
            - AppBundle\Repository\ORM\ImageRepository

    app.manager.image_manager:
        class: AppBundle\Manager\ImageManager
        arguments:
            - "@app.repository.orm.image_repository

在第一个服务中,参数中应该有实体类,而不是存储库类!我因疏忽而犯了这个错误。所以第一个服务定义应该看起来像这样:

app.repository.orm.image_repository:
    class: Doctrine\ORM\EntityRepository
    factory: ['@doctrine.orm.default_entity_manager', getRepository]
    arguments:
        - AppBundle\Entity\Image