doumingo04696 2015-01-18 13:45
浏览 7

SonataMediaBundle:GalleryHasMedia的存储库类

I am trying to controll my media entities by creating a repository.

How to create a repository for the GalleryHasMedia class?

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();
    }
}

Application\Sonata\MediaBundle\Resources\config\doctrine\GalleryHasMedia.orm.xml

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

Application\Sonata\MediaBundle\Entity\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
{
    ...
}

Error:

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

Please tell how to fix it?

config.yml

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

When I write a non-existent class here: GalleryHasMedia.orm.xml there are error messages.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大