如何在Symfony2项目中安装Doctrine Extensions

Fae*_*ery 14 doctrine symfony

我想这是一个非常琐碎和愚蠢的问题,但我不知道如何在我的Symfony2项目中安装Doctrine Extensions - https://github.com/beberlei/DoctrineExtensions.因为MONTH,YEAR功能,我需要它们.我应该把文件夹放在哪里?我应该把整个DoctrineExtensions文件夹?在哪里写这个:

<?php

$classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', "/path/to/extensions");
$classLoader->register(); 
Run Code Online (Sandbox Code Playgroud)

在一个单独的文件?把它放在哪里以及如何调用它?

然后就是我需要使用它们:

public function findOneByYearMonthDay($year, $month, $day)
{
    $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');
Run Code Online (Sandbox Code Playgroud)

非常感谢你提前和再次抱歉这个问题,但我找不到一个教程(这让我感到更加内疚,因为我觉得它甚至没有教程时太微不足道了)

Ale*_* B. 29

你可以通过composer安装它.只需将它添加到您的composer.json然后php composer.phar update beberlei/DoctrineExtensions

"beberlei/DoctrineExtensions": "*",
Run Code Online (Sandbox Code Playgroud)

然后,您可以将功能注册到ORM

doctrine:
    orm:
      auto_generate_proxy_classes: %kernel.debug%
      entity_managers:
        default:
          auto_mapping: true
          dql:
            datetime_functions:
              MONTH: DoctrineExtensions\Query\Mysql\Month
              YEAR: DoctrineExtensions\Query\Mysql\Year
Run Code Online (Sandbox Code Playgroud)

  • 您可以从http://symfony.com/doc/current/doctrine/custom_dql_functions.html列出基本功能. (2认同)