Doctrine2加载DoctrineExtensions

时间:2017-09-27 08:41:40

标签: doctrine-orm doctrine-extensions

我想在Doctrine2查询构建器中使用DAY()和YEAR()函数。但不知怎的,我一直在犯错:

$totalHits = $this->registry->entityManager->getRepository('Entities\Hit')
->createQueryBuilder('h')
->select('DAY(h.date) AS day')
->groupBy('day')
->getQuery()->getResult();`

PHP代码:

$classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', __DIR__.'/../vendor/beberlei/DoctrineExtensions');
$classLoader->register();

通过编辑器或自动加载器加载doctrineExtensions无法修复它:

onCreate

我是错误地加载了DoctrineExtensions还是还有别的东西?

1 个答案:

答案 0 :(得分:0)

固定。添加:

$entityManagerConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Sqlite\Year');
$entityManagerConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Sqlite\Month');
$entityManagerConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Sqlite\Day');

解决了问题