问题
I get the error Attempted to load class "Month" from namespace "DoctrineExtensions\Query\Mysql". Did you forget a "use" statement for another namespace
when i'm trying to create a query that fetch data by year and month
Inside my repository
public function getCongePris($mois,$annee,$matricule)
{
$emConfig = $this->_em->getConfiguration();
$emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
$emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
$qb = $this->createQueryBuilder('co')->leftJoin('co.personnel','p');
$qb->select('co')
->where('p.matricule= :matricule')->andWhere('co.statutDemande=:statut ')
->andWhere('MONTH( co.debutConge)=:mois')->andWhere('YEAR(co.debutConge)=:annee');
$qb->setParameter('annee',$annee)->setParameter('mois',$mois)->setParameter('matricule',$matricule)->setParameter('statut','ACCEPTE');
$conges = $qb->getQuery()->getResult();
return $conges;
}
Inside my config.yml
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
dql:
string_functions:
MONTH: DoctrineExtensions\Query\Mysql\Month
YEAR: DoctrineExtensions\Query\Mysql\Year
回答1:
You must install extension which will add required class to the Symfony.
This bundle should do the job: https://github.com/beberlei/DoctrineExtensions
composer require beberlei/DoctrineExtensions
来源:https://stackoverflow.com/questions/42319208/attempted-to-load-class-month-from-namespace-doctrineextensions-query-mysql