Symfony2: Unable to use DoctrineExtensions Mysql Year function
doctrine-orm, mysql, php, symfony
Solution
Have you registered the YEAR function to the Doctrine configuration?
$this->getEntityManager()->getConfiguration()->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
Problem
I have so far been unsuccessful in implementing the beberlei DoctrineExtensions. I need the MySQL Year() function. Error is: Expected known function, got 'Year' So I must be missing something. What? Here's what I've gotten so far: Extensions are installed in `..\vendor\beberlei\lib\DoctrineExtensions` app/autoload.php reads: ``` use Doctrine\Common\Annotations\AnnotationRegistry; $loader = require __DIR__.'/../vendor/autoload.php'; $loader->add('DoctrineExtensions', __DIR__.'/../vendor/beberlei/lib/DoctrineExtensions'); // intl if (!function_exists('intl_get_error_code')) { require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php'; $loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs'); } AnnotationRegistry::registerLoader(array($loader, 'loadClass')); return $loader; ``` Year function use: ``` class ClientRepository extends EntityRepository { public function activeStatus($year, $status) { $em = $this->getEntityManager(); $query = $em ->createQuery('select max(Year(ct.contact_date)) CY, c.active from ManaClientBundle:Contacts ct join ManaClientBundle:Client c on ct.cid = c.id group by id') ->getResult(); return $em->createQuery("select CY, count(CY) Status from $query where CY = $year and active = '$status'") ->getResult(); } } ```