如何在 Symfony2 项目中安装 Doctrine Extensions [英] How to install Doctrine Extensions in a Symfony2 project
问题描述
我猜这真的是个琐碎而愚蠢的问题,但我不知道如何安装 Doctrine Extensions - 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 DoctrineCommonClassLoader('DoctrineExtensions', "/path/to/extensions");
$classLoader->register();
在一个单独的文件中?把它放在哪里以及如何称呼它?
In a separate file? Where to put it and how to call it?
然后这就是我需要使用它们的全部内容:
And then is this all I need to use them:
public function findOneByYearMonthDay($year, $month, $day)
{
$emConfig = $this->getEntityManager()->getConfiguration();
$emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensionsQueryMysqlYear');
$emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensionsQueryMysqlMonth');
$emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensionsQueryMysqlDay');
在此先非常感谢您的问题,再次抱歉,但我找不到教程(这让我感到更加内疚,因为我想即使没有教程也太琐碎了)
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 安装它.只需将其添加到您的 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: DoctrineExtensionsQueryMysqlMonth
YEAR: DoctrineExtensionsQueryMysqlYear
这篇关于如何在 Symfony2 项目中安装 Doctrine Extensions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!