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


Did you forget a "use" statement for another namespace?

目前,我使用Symfony 3,我在开发方面没有任何问题。

当我把我的网站放在生产中时,我有这个错误:

Attempted to load class "ZoneRepository" from namespace "AppBundle'Repository".
Did you forget a "use" statement for another namespace?

区域存储库的代码:

<?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();
    }
}

我的结构图像

我试过了:

use Doctrine'ORM'EntityRepository;
/**
 * ZoneRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class ZoneRepository extends EntityRepository

但它不起作用

你有什么想法吗?

谢谢


溶液:将所有存储库文件放入实体折叠中。不要忘记更改

* @ORM'Entity(repositoryClass="AppBundle'Entity'ZoneRepository")

当我的文件名和类名不同时,我遇到了此错误。

我遇到了同样的问题,请检查文件的位置是否与您的命名空间具有相同的路径

例如:

use UtilBundle'Entity'Base'BaseClass;
...
class TipoExpediente extends BaseClass {

mi基类在:/src/UtilBundle/Entity/Base/BaseClass.php

清除缓存并检查,使用

php app/console cache:clear --env=prod
php app/console cache:clear --env=dev

如有必要,调整文件权限,禁用开发环境缓存以提高性能和易用性,生产环境针对速度进行了优化