你忘记了"使用"另一个命名空间的语句?

时间:2016-07-06 00:27:06

标签: php symfony

此时,我使用的是Symfony 3,我在开发中没有任何问题。

当我将我的网站放入prod时,我有这个错误:

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

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

img of my stucture

我试过了:

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")

3 个答案:

答案 0 :(得分:3)

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

例如:

use UtilBundle\Entity\Base\BaseClass;

...

class TipoExpediente extends BaseClass {

和mi基类位于:/src/UtilBundle/Entity/Base/BaseClass.php

答案 1 :(得分:1)

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

答案 2 :(得分:0)

清除缓存并检查,使用

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

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

相关问题