Doctrine2 加载 DoctrineExtensions
Doctrine2 loading DoctrineExtensions
我想在我的 Doctrine2 查询生成器中使用 DAY() 和 YEAR() 函数。但不知何故我不断收到错误:
Fatal error: Uncaught Doctrine\ORM\Query\QueryException: SELECT DAY(h.date) AS day FROM Entities\Hit h GROUP BY day in
PHP代码:
$totalHits = $this->registry->entityManager->getRepository('Entities\Hit')
->createQueryBuilder('h')
->select('DAY(h.date) AS day')
->groupBy('day')
->getQuery()->getResult();`
通过作曲家或通过自动加载器加载 doctrineExtensions 无法修复它:
$classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', __DIR__.'/../vendor/beberlei/DoctrineExtensions');
$classLoader->register();
是我错误地加载了 DoctrineExtensions 还是有其他问题?
已修复。添加:
$entityManagerConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Sqlite\Year');
$entityManagerConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Sqlite\Month');
$entityManagerConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Sqlite\Day');
解决了问题
我想在我的 Doctrine2 查询生成器中使用 DAY() 和 YEAR() 函数。但不知何故我不断收到错误:
Fatal error: Uncaught Doctrine\ORM\Query\QueryException: SELECT DAY(h.date) AS day FROM Entities\Hit h GROUP BY day in
PHP代码:
$totalHits = $this->registry->entityManager->getRepository('Entities\Hit')
->createQueryBuilder('h')
->select('DAY(h.date) AS day')
->groupBy('day')
->getQuery()->getResult();`
通过作曲家或通过自动加载器加载 doctrineExtensions 无法修复它:
$classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', __DIR__.'/../vendor/beberlei/DoctrineExtensions');
$classLoader->register();
是我错误地加载了 DoctrineExtensions 还是有其他问题?
已修复。添加:
$entityManagerConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Sqlite\Year');
$entityManagerConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Sqlite\Month');
$entityManagerConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Sqlite\Day');
解决了问题