zend framework and doctrine 2 - save and download

2019-08-16 01:33发布

问题:

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!