如何在Symfony2项目中安装教义扩展 [英] How to install Doctrine Extensions in a Symfony2 project

查看:117
本文介绍了如何在Symfony2项目中安装教义扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I guess that this is really trivial and stupid question, but I don't know how to install Doctrine Extensions - https://github.com/beberlei/DoctrineExtensions in my Symfony2 project. I need them because of the MONTH, YEAR functions. Where should I put their folder? And should I put the whole DoctrineExtensions folder? And where to write this:

<?php

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

在单独的文件中?放在哪里,怎么称呼?

In a separate file? Where to put it and how to call it?

然后我需要使用它们:

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');

提前非常感谢您,再次感谢您的问题,但我找不到教程(这使我感到更加内疚,因为我甚至没有教程,这太简单了)

Thank you very much in advance and sorry once again for the question, but I couldn't find a tutorial (which makes me feel even more guilty, because I guess it's too trivial when there isn't even a tutorial)

推荐答案

您可以通过作曲家安装它。只需将其添加到您的composer.json中,然后再将 php composer.phar更新beberlei / DoctrineExtensions

You can install it via composer. Just add it to your composer.json and then php composer.phar update beberlei/DoctrineExtensions

"beberlei/DoctrineExtensions": "*",

然后你可以注册函数你的ORM

Then you can register functions to your 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

这篇关于如何在Symfony2项目中安装教义扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆