duanhunlou7051 2016-07-25 13:57
浏览 47

在show动作中显示媒体

I use Sonata to make an app and I am facing some problem with MediaBundle. I Have two entities :

Product & ProductImage

Inside Product I have this :

/**
 * @ORM\ManyToMany(targetEntity="ProductImage", cascade={"persist"}, fetch="LAZY", indexBy="ASC")
 */
protected $medias;

Inside ProductImage :

/**
 * @ORM\ManyToOne(targetEntity="Product", cascade={"persist"}, fetch="LAZY")
 */
protected $Product;

/**
 * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Media\Media", cascade={"persist"}, fetch="LAZY")
 */
protected $image;

public function __toString()
{
    global $kernel;

    $provider = $kernel->getContainer()->get($this->getImage()->getProviderName());
    return $provider->generatePublicUrl($this->getImage(),'small');
}

In my ProductAdmin.php file :

public function configureShowFields(ShowMapper $showMapper)
{
    $showMapper
        ->add('name')
        ->end()
        ->with('Medias', array('class' => 'col-md-12'))
        ->add('medias', 'sonata_type_collection', array(), array(
            'inline' => 'table',
            'sortable'  => 'position'
        )) 
        ->end();
}

When I go to the show page ( .../product/6/show), I have all my information correctly display but medias is just a list of public URL. How can I display each image instead of URL ?

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?