Additional DQL functions for Doctrine2
RAND()
ref
MONTH()
ref
substr(string, from, count)
ref
Just add the package to your composer.json
{
"require": {
"morontt/doctrine-functions": "dev-master"
}
}
According to the Doctrine documentation you can register the functions in this package this way.
<?php
$config = new \Doctrine\ORM\Configuration();
$config->addCustomNumericFunction('rand', 'Morontt\DQL\Numeric\Rand');
?>
With symfony 2 you can register you functions in the config.yml
file.
doctrine:
orm:
entity_managers:
default:
dql:
numeric_functions:
rand: Morontt\DQL\Numeric\Rand
datetime_functions:
month: Morontt\DQL\DateTime\Month
string_functions:
substr: Morontt\DQL\String\Substr