SonataMediaBundle:GalleryHasMedia的存储库类

时间:2015-01-18 13:45:22

标签: php symfony doctrine sonata-media-bundle

我试图通过创建存储库来控制我的媒体实体。

如何为GalleryHasMedia类创建存储库?

namespace Application\Sonata\MediaBundle\Repository;

use Doctrine\ORM\EntityRepository;

class GalleryHasMediaRepository extends EntityRepository
{
    /**
     * @param integer $galleryId
     * @return array
     */
    private function findMediaOfGallery($galleryId)
    {
        $qb = $this->getEntityManager()->createQueryBuilder();
        $qb->select('gm')
           ->from('ApplicationSonataMediaBundle:GalleryHasMedia', 'gm')
           ->where('gm.gallery_id = :gallery')
           ->setParameters(['gallery' => $galleryId]);
        return $qb->getQuery()->getResult();
    }
}

应用程序\奏\ MediaBundle \资源\配置\教义\ GalleryHasMedia.orm.xml

repository-class="Application\Sonata\MediaBundle\Repository\GalleryHasMediaRepository"

应用程序\奏\ MediaBundle \实体\ GalleryHasMedia.php

namespace Application\Sonata\MediaBundle\Entity;

use Sonata\MediaBundle\Entity\BaseGalleryHasMedia as BaseGalleryHasMedia;

use Sonata\MediaBundle\Model\GalleryInterface as GalleryInterface;
use Sonata\MediaBundle\Model\MediaInterface as MediaInterface;

class GalleryHasMedia extends BaseGalleryHasMedia
{
    ...
}

错误:

Undefined method 'findMediaOfGallery'. The method name must start with either findBy or findOneBy! 

请告诉我们如何修理它?

config.yml

# Doctrine Configuration
doctrine:
    orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    auto_mapping: true

当我在这里写一个不存在的类时:GalleryHasMedia.orm.xml有错误消息。

0 个答案:

没有答案