ulduz114
ulduz114

Reputation: 1180

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

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

Upvotes: 0

Views: 1254

Answers (1)

Kees Schepers
Kees Schepers

Reputation: 2248

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!

Upvotes: 1

Related Questions