Search code examples
doctrine-ormzend-framework2dql

How to add a custom DQL function in Doctrine 2 using Zend Framework 2


Well the question pretty much lies in the title. I've read the docs and what I can't find out is how to register the function to my ORM Configuration.

Any help here? Thanks!

Edit: Okay I've done it as Sam said, and made my own class and registered it like

            'numeric_functions' => array(
                'LOG10'  => 'Admin\Model\Log10',
            ),

However it can't find the class and gives the error

Class 'Admin\Model\Log10' not found in C:\webserver\apache\htdocs\test\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php on line 3322

Any idea on why this happens?


Solution

  • Actually the link that @foozy gave you is all that you'd need. You simply extend your doctrine configuration array:

    return array(
        'doctrine' => array(
            'connection'    => array(
                'orm_default' => array(
                    // Foo
                )
            ),
            'configuration' => array(
                'orm_default' => array(
                    'numeric_functions' => array(
                        'MD5'  => 'DoctrineExtensions\Query\Mysql\Md5'
                    ),
                    'datetime_functions' => array(),
                    'string_functions'   => array(),
                    'metadata_cache'     => 'filesystem',
                    'query_cache'        => 'filesystem',
                    'result_cache'       => 'filesystem',
                )
            )
        )
    );