简体   繁体   English

在Sonata Admin中的实体中包括媒体类型

[英]Include a media type in an Entity from Sonata Admin

I'm making an Entity which is called Article, it should have some text, a video and a couple of images. 我正在创建一个名为Article的实体,它应该包含一些文本,视频和一些图像。 For the latter I'm doing it by allowing the user to create a media and then include the images there, now for the question... how do I relate that media to the article? 对于后者,我是通过允许用户创建媒体,然后在其中包含图像的方式来完成的,现在是一个问题……我如何将媒体与文章联系起来? Do I have a "media list picker" to choose from? 我是否有“媒体列表选择器”可供选择?

To include Sonata MediaBundle in the Admin Bundle, you'll need to add for example an Image field to your Article entity. 要将Sonata MediaBundle包含在Admin Bundle中,您需要向“ Article”实体添加例如Image字段。

/**
 * @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Gallery")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="image", referencedColumnName="id")
 * })
 */
private $image;

And then refer to it in your ArclicleAdmin : 然后在ArclicleAdmin中引用它:

->add('image', 'sonata_type_model_list', array('required' => false))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM