zend framework and doctrine 2 - save and download image from database to image field

ⅰ亾dé卋堺 提交于 2020-01-06 13:30:03

问题


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?

Thanks


回答1:


I think this: https://gist.github.com/525030/38a0dd6a70e58f39e964ec53c746457dd37a5f58

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.

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.
}
?>

Good luck!



来源:https://stackoverflow.com/questions/7404801/zend-framework-and-doctrine-2-save-and-download-image-from-database-to-image-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!