morontt/doctrine-functions

Doctrine2的附加DQL函数

dev-master 2016-10-14 12:15 UTC

This package is auto-updated.

Last update: 2024-09-29 04:42:20 UTC


README

Doctrine2的附加DQL函数

数值函数

日期时间函数

字符串函数

  • substr(string, from, count) 参考

安装

只需将此包添加到您的composer.json

{
    "require": {
        "morontt/doctrine-functions": "dev-master"
    }
}

集成

1) 仅 Doctrine

根据Doctrine 文档,您可以这样注册此包中的函数。

<?php
$config = new \Doctrine\ORM\Configuration();
$config->addCustomNumericFunction('rand', 'Morontt\DQL\Numeric\Rand');
?>

2) 使用 Symfony 2

在 symfony 2 中,您可以在 config.yml 文件中注册您的函数。

doctrine:
    orm:
        entity_managers:
            default:
                dql:
                    numeric_functions:
                        rand: Morontt\DQL\Numeric\Rand
                    datetime_functions:
                        month: Morontt\DQL\DateTime\Month
                    string_functions:
                        substr: Morontt\DQL\String\Substr