我有个错误:
致命错误:在第578行的C:\wamp\www\videotheque\vendor\document\lib\document\orm\entitymanager.php中找不到类“gsyle39\videothequebundle\repository\genrerepository”
不过,我将repository类的名称添加到实体的映射定义中:

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

以下是我的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);
    }
}

最后,这是我的控制器中用于调用我的客户“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
        ));
   }

最佳答案

您的存储库有as namespacenamespace gstyle39\VideothequeBundle\Entity;,注释中说它应该是namespace gstyle39\VideothequeBundle\Repository;
另外,请确保将其放在src/gstyle39/VideothequeBundle/Repository目录下。

07-25 21:21
查看更多