Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempted to load class "Month" from namespace "DoctrineExtensions\Query\Mysql". Did you forget a "use" statement for another namespace

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
like image 849
Kahn Sparkle Avatar asked Feb 18 '17 18:02

Kahn Sparkle


1 Answers

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
like image 137
HelpNeeder Avatar answered Nov 19 '22 11:11

HelpNeeder