Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement beberlei doctrine extensions in zend framework 2

i dont know how to integrate the beberlei doctrine-extensions: https://github.com/beberlei/DoctrineExtensions in Zend Framework 2 with Doctrine Module. I installed it with composer:

"beberlei/DoctrineExtensions": "dev-master"

I tried in my module.config.php from th application module:

'doctrine' => array(
    'driver' => array(
         __NAMESPACE__ .'_driver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/'.__NAMESPACE__.'/Entity')
        ),
        'orm_default' => array(
            'drivers' => array(
               __NAMESPACE__.'\Entity' => __NAMESPACE__. '_driver'

            )
        )
    ),
    'configuration' => array(
        'orm_default' => array(
            'string_functions' => array(
                'GroupConcat' => '/vendor/beberlei/DoctrineExtensions\Query\MsySql\GroupConcat'
            )
        )
    )
),

but this Exception was thrown:

Fatal error: Class '/vendor/beberlei/DoctrineExtensions\Query\MsySql\GroupConcat' not found

like image 843
Marcus Wolf Avatar asked Apr 16 '14 18:04

Marcus Wolf


2 Answers

The configuration doesn't need to reference the /vendor/beberlei folder as this is handled by the autoloader. The configuration should probably look something like this :

'doctrine' => array(
    'driver' => array(
         __NAMESPACE__ .'_driver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/'.__NAMESPACE__.'/Entity')
        ),
        'orm_default' => array(
            'drivers' => array(
               __NAMESPACE__.'\Entity' => __NAMESPACE__. '_driver'

            )
        )
    ),
    'configuration' => array(
        'orm_default' => array(
            'string_functions' => array(
                'GroupConcat' => 'DoctrineExtensions\Query\Mysql\GroupConcat'
            )
        )
    )
),
like image 187
Stephen Avatar answered Sep 29 '22 20:09

Stephen


After installing with Composer

"beberlei/DoctrineExtensions": "dev-master"

use this code in your service class:

$config = $this->getEntityManager()->getConfiguration();
$config->addCustomStringFunction('GROUP_CONCAT', 'DoctrineExtensions\Query\MySq\GroupConcat');

now you can use 'GROUP_CONCAT' in your DQL like this:

    $dql = "SELECT GROUP_CONCAT(elem.name) FROM ..... GROUP BY ...";
$query = $this->getEntityManager()->createQuery($dql);
return $query->getArrayResult();
like image 36
Stas Avatar answered Sep 29 '22 21:09

Stas