【问题标题】:Did you forget a "use" statement for another namespace?您是否忘记了另一个名称空间的“使用”语句?
【发布时间】:2016-11-07 23:03:52
【问题描述】:

目前,我使用的是 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

但它不起作用

你有想法吗?

谢谢


解决方案: 您将所有存储库文件放在 Entity 折叠中。不要忘记更改

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

【问题讨论】:

  • 您是否清除了 prod env 的缓存?
  • 你能告诉我们实体文件是什么样的吗?可能存在一些参考问题
  • 您确定文件名使用相同的大小写吗?当您在 windows 上使用 dev 模式和在 linux 上使用 prod 模式时,这通常会附加。
  • 是的,您可以查看结构的 img 名称为:AppBundle/Repository 中的“ZoneRepository”
  • 我已经通过composer生成了存储库,你有什么想法吗?

标签: php symfony


【解决方案1】:

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

例如:

use UtilBundle\Entity\Base\BaseClass;

...

class TipoExpediente extends BaseClass {

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 是的..这为我修好了!
    【解决方案3】:

    清除缓存并检查,使用

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

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

    【讨论】:

    • 已经用 php bin/console 缓存清除了我的缓存:clear --env=prod --no-debug 和 perms : chmod 777 cache -R chmod 777 logs -R
    猜你喜欢
    • 2019-11-18
    • 2020-05-24
    • 2017-02-12
    • 2015-11-07
    • 2019-03-23
    • 2019-10-09
    • 2021-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多