如何坚持使用教义的形象 [英] How do I persist Images with Doctrine

查看:170
本文介绍了如何坚持使用教义的形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Doctrine2可以这样吗?



我如何做?



最好的问候,
bodo

解决方案>

使用@File类型的ODM设置,这是非常简单的。



对于ORM实体,我将看到如此创建一个列。



注意:使用此链接将Blob类型添加到Doctrine2



使用Symfony 2在Doctrine 2中添加BLOB类型

  / ** @ ORM\Column(type =blob)* / 
protected $ imageData;

/ ** @ ORM\Column(type =string)* /
protected $ imageType;

/ ** @ ORM\Column(type =int)* /
protected $ imageLength;

/ ** @ ORM\Column(type =int)* /
protected $ imageWidth;

/ ** @ ORM\Column(type =int)* /
protected $ imageHeight;

然后将该属性设置为图像的原始数据。您将需要存储长度,内容类型,宽度和高度以及原始数据,以便您可以创建正确的标题来检索图像并将其显示在浏览器中或下载。



这应该足够让你开始正确的路径,或决定不打扰。


I want to persist an Image in my Article Entity.

Is this possible with Doctrine2?

How do i do this?

Best Regards, bodo

解决方案

This is pretty simple using the ODM setup with the @File type.

For a ORM entity, I would look at creating a column like so.

NOTE: Use this link to add the blob type to Doctrine2

How add BLOB type in Doctrine 2 using Symfony 2

/** @ORM\Column(type="blob") */
protected $imageData;

/** @ORM\Column(type="string") */
protected $imageType;

/** @ORM\Column(type="int") */
protected $imageLength;

/** @ORM\Column(type="int") */
protected $imageWidth;

/** @ORM\Column(type="int") */
protected $imageHeight;

Then set that property with the raw data of the image. You will want to store things like the length, content-type, width and height along with the raw data so that you can create the right headers to retrieve the image and display it in the browser or download it.

That should be enough to get you started on the right path, or decide not to bother.

这篇关于如何坚持使用教义的形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆