Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 - Custom repository not found

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
        ));
   }
like image 856
Adrien G Avatar asked Feb 02 '26 15:02

Adrien G


1 Answers

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.

like image 73
Lumbendil Avatar answered Feb 04 '26 04:02

Lumbendil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!