doumang20060820 2012-07-31 14:15
浏览 46
已采纳

Symfony2 - 找不到自定义存储库

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条回答 默认 最新

  • dongyi5070 2012-07-31 14:18
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?