php - Symfony2 - 找不到自定义存储库

标签 php symfony doctrine-orm repository

我有这个错误:

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

不过,我将存储库类的名称添加到我的实体的映射定义中:

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

这是我的流派库:

<?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”的 Controller 中的方法:

public function getListGenresAction(){

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

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

最佳答案

您的存储库具有命名空间 namespace gstyle39\VideothequeBundle\Entity; 并且注释表明它应该是 namespace gstyle39\VideothequeBundle\Repository;

此外,确保将它放在 src/gstyle39/VideothequeBundle/Repository 目录下。

关于php - Symfony2 - 找不到自定义存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11742201/

相关文章:

php - 如何用四列回显两行

php - 这个 preg_replace 中的 $1$2$4 是什么意思?

security - symfony2 安全角色

php - 学说 2 : How to search for an entity by its association's value?

Symfony2实体Time类型返回格式

php - MySQL 数据库中的文本采用 ISO-8859-1(拉丁文)编码,但应为 UTF-8

php - 清理和验证 php 表单

javascript - Symfony Assetic-URL中的part_1

symfony - FOSUserBundle 单元测试

php - Symfony2 中的 Doctrine 多次插入超时