3

I've this error:

Fatal error: Class 'gsyle39\VideothequeBundle\Repository\GenreRepository' not found in C:\wamp\www\Videotheque\vendor\doctrine\lib\Doctrine\ORM\EntityManager.php on line 578

Nevertheless, I add the name of the repository class to the mapping definition of my entity :

/**
* gsyle39\VideoThequeBundle\Entity\Genre
*
* @ORM\Table()
*
* @ORM\Entity(repositoryClass="gsyle39\VideothequeBundle\Repository\GenreRepository")
*/
class Genre
{
   ...
}

Here is my GenreRepository :

<?php

namespace gstyle39\VideothequeBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * GenreRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class GenreRepository extends EntityRepository
{
    public function myfindAll()
    {
        $genres = $this->_em->createQueryBuilder('g')
            // leftJoin because I need all the genre
            ->leftJoin('g.films', 'f')
            ->addSelect('COUNT(f)')
            ->groupBy('g')
            ->getQuery()
            ->getArrayResult();

        // $genres contains all the genres and the associated movies
        return ($genres);
    }
}  

And finally this is the method in my controller I use for calling my custome "findALL" :

public function getListGenresAction(){

        $liste_genres = $this->getDoctrine()
                             ->getEntityManager()
                             ->getRepository('gstyle39VideothequeBundle:Genre')
                             ->myFindAll;

        return $this->render('gstyle39VideothequeBundle:Videotheque:test.html.twig', array(
            'genres' => $liste_genres
        ));
   }

1 Answer 1

3

Your repository has as namespace namespace gstyle39\VideothequeBundle\Entity; and the annotation says it should be namespace gstyle39\VideothequeBundle\Repository;.

Also, make sure you put it under src/gstyle39/VideothequeBundle/Repository directory.

Sign up to request clarification or add additional context in comments.

3 Comments

You are right, I had a wrong namespace but it doesn't solve the problem :s
Try to delete app/cache/* folders and reload the application.
It's in the directory I commented? If so, is the error still the same? Double-check folder names, including upper-case/lower-case letters, match the namespace. Also I noticed i had a typo in the directory I said.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.