试图加载课程"月"来自命名空间" DoctrineExtensions \ Query \ Mysql"。你忘记了"使用"另一个命名空间的语句

时间:2017-02-18 18:42:20

标签: php symfony doctrine

当我尝试创建按年份和月份获取数据的查询时,我收到错误Attempted to load class "Month" from namespace "DoctrineExtensions\Query\Mysql". Did you forget a "use" statement for another namespace

在我的资料库中

 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;
    }

在我的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 个答案:

答案 0 :(得分:4)

您必须安装将为Symfony添加所需类的扩展名。

此捆绑包应该完成这项工作:https://github.com/beberlei/DoctrineExtensions

composer require beberlei/DoctrineExtensions