私はこのエラーがあります:
致命的なエラー:クラス'gsyle39 \ VideothequeBundle \ Repository \ GenreRepository'がC:\ wamp \ www \ Videotheque \ vendor \ doctrine \ lib \ Doctrine \ ORM\EntityManager.phpの578行に見つかりません
それでも、リポジトリクラスの名前をエンティティのマッピング定義に追加します。
/**
* 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
));
}