Doctrine orm 如何在Doctrine2中选择年()月()日()

Doctrine orm 如何在Doctrine2中选择年()月()日(),doctrine-orm,symfony,Doctrine Orm,Symfony,我使用此代码选择对象案例月 这是我在存储库中的功能 public function findProductByCustomerIdGroupByCodeMc($id,$magasin,$periode) { $emConfig = $this->getEntityManager()->getConfiguration(); $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExt

我使用此代码选择对象案例月 这是我在存储库中的功能

    public function findProductByCustomerIdGroupByCodeMc($id,$magasin,$periode)
    {

    $emConfig = $this->getEntityManager()->getConfiguration();
        $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
        $emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
        $emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');

        $qb = $this->createQueryBuilder('lead')
                    ->select('lead')
                    ->from('BOGeneralBundle:EtLeads', 'l')
                     if($periode != "0") 
                     {
                      $qb->andWhere('MONTH(l.dataCreated) = :periode')
                             ->setParameter('periode', $periode);
                     }
        return$qb->getQuery()->getResult();
    }
把传导放进去,因为我可以选择所有月份,它的值=0 页面将显示此消息

致命错误:找不到类“DoctrineExtensions\Query\Mysql\Month”


对于Doctrine2,您必须注册自己的函数来识别DQL中的YEAR()MONTH()和DAY()

为此,您可以通过composer安装bundle。只需将它添加到您的
composer.json
,然后
php composer.phar更新beberlei/DoctrineExtensions

"beberlei/DoctrineExtensions": "*",
然后您可以将函数注册到您的ORM

doctrine:
    orm:
      auto_generate_proxy_classes: %kernel.debug%
      entity_managers:
        default:
          auto_mapping: true
          dql:
            datetime_functions:
              DAY: DoctrineExtensions\Query\Mysql\Day
              MONTH: DoctrineExtensions\Query\Mysql\Month
              YEAR: DoctrineExtensions\Query\Mysql\Year

这篇文章也谈到了这一点。

DoctrineExtensions\Query\Mysql\Month
类存在吗?我应该创建它吗?如果是,请看我的答案:)什么是$periode类型?是整数还是什么??