zend框架和原则2 - 保存和下载图像从数据库到图像字段 [英] zend framework and doctrine 2 - save and download image from database to image field

查看:93
本文介绍了zend框架和原则2 - 保存和下载图像从数据库到图像字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用zf和doctrine 2,并且尝试将图像保存到数据库中的一个字段并从mysql blob字段下载图像时遇到问题?

I'm using zf and doctrine 2 in an application and I'm having a problem with trying to save images to a field in my database and download image from mysql blob field?

有没有人有一个小例子,我可以工作?

Does anyone have a small example that I could work from?

谢谢

推荐答案

我认为这样: https://gist.github.com/525030/38a0dd6a70e58f39e964ec53c746457dd37a5f58

正是你想要的因为blob数据类型不支持默认值,您可以将自己的数据类型添加到Doctrine2中。从链路使用的示例可以为一个BLOB字段设置@Column(类型= 斑点)。

Is exactly what you want. Because the blob datatype is not default supported you can add your own datatypes to Doctrine2. Using the example from the link you can set @Column(type="blob") for a BLOB field.

如果您使用Bisna胶水用于集成Doctrine2和ZF你可以做这样的事情在你的引导:

If you use the Bisna glue for integrating Doctrine2 and ZF you could do something like this in your bootstrap:

<?php
protected function _initDoctrineExtraDatatypes() {
    $this->bootstrap('doctrine');

    $doctrine = $this->getPluginResource('doctrine');
    $em = $doctrine->getEntityManager();

    // types registration
    Doctrine\DBAL\Types\Type::addType('blob', 'Doctrine\DBAL\Types\Blob');
    $em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('BLOB', 'blob');        

    //off course you could ask some more types here you want to be integrated.
}
?>

祝你好运!

这篇关于zend框架和原则2 - 保存和下载图像从数据库到图像字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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