Antoine Bourlart
Antoine Bourlart

Reputation: 781

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

At this moment, I use Symfony 3, and I don't have any problem in dev.

When I have put my website in prod, i have this error :

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

Code of the 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

I tried :

use Doctrine\ORM\EntityRepository;

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

But it not works

Have you an idea ?

Thanks


Solution : You put all repositories files in your Entity fold. Don't forget change the

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

Upvotes: 2

Views: 17660

Answers (3)

Maxim Strutinskiy
Maxim Strutinskiy

Reputation: 531

I had this error when my file name and class name is different.

Upvotes: 6

I had the same problem, check that the location of the files have the same path as your namespace

for example:

use UtilBundle\Entity\Base\BaseClass;

...

class TipoExpediente extends BaseClass {

and mi base class is in: /src/UtilBundle/Entity/Base/BaseClass.php

Upvotes: 4

some_groceries
some_groceries

Reputation: 1192

clear the cache and check, use

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

adjust file permission if necessary,dev environment cache is disabled for performance and ease of use, prod environment is optimized for speed

Upvotes: 0

Related Questions