2017-09-27 55 views
0

我想在我的Doctrine2查詢生成器中使用DAY()和YEAR()函數。但不知何故,我不斷收到錯誤:Doctrine2 loading學習擴展

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是錯誤的還是還有別的?

回答

0

固定。添加:

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

解決了這個問題