您是否忘记了另一个命名空间的“use”语句?

Ant*_*art 2 php symfony

目前,我使用的是Symfony 3,并且在开发中没有任何问题。

当我将网站放入产品中时,出现以下错误:

Attempted to load class "ZoneRepository" from namespace "AppBundle\Repository".
Did you forget a "use" statement for another namespace?
Run Code Online (Sandbox Code Playgroud)

ZoneRepository 的代码:

<?php

namespace AppBundle\Repository;

/**
 * ZoneRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class ZoneRepository extends \Doctrine\ORM\EntityRepository
{
    /**
     * @return array
     */
    public function getZones()
    {
        $qb = $this->createQueryBuilder('z');

        $qb
            ->select('z')
            ->where('z.active = 1')
            ->orderBy('z.id', 'DESC');

        return $qb->getQuery()->getResult();
    }
}
Run Code Online (Sandbox Code Playgroud)

我的结构的img

我试过 :

use Doctrine\ORM\EntityRepository;

/**
 * ZoneRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class ZoneRepository extends EntityRepository
Run Code Online (Sandbox Code Playgroud)

但它不起作用

你有主意吗?

谢谢


解决方案:将所有存储库文件放入实体文件夹中。不要忘记更改

* @ORM\Entity(repositoryClass="AppBundle\Entity\ZoneRepository")
Run Code Online (Sandbox Code Playgroud)

Max*_*kiy 6

当我的文件名和类名不同时,出现此错误。