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

主宰稳场 提交于 2021-02-19 01:13:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!