Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 811af56

Browse files
healdropperweaverryan
authored andcommitted
DQL custom functions on doctrine reference page
Seems that there is two possibilities to configure custom DQL functions It should be clearified in doctrine reference page because It may confuse some people if they just read the cookbook: http://symfony.com/doc/current/cookbook/doctrine/custom_dql_functions.html
1 parent 801c756 commit 811af56

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

reference/configuration/doctrine.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,42 @@ Each connection is also accessible via the ``doctrine.dbal.[name]_connection``
411411
service where ``[name]`` is the name of the connection.
412412

413413
.. _DBAL documentation: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html
414+
415+
Register Custom DQL Functions
416+
-----------------------------
417+
418+
Doctrine allows you to specify custom DQL functions. For more information
419+
on this topic, read Doctrine's cookbook article "`DQL User Defined Functions`_".
420+
421+
In Symfony, you can register your custom DQL functions as follows:
422+
423+
.. code-block:: yaml
424+
doctrine:
425+
orm:
426+
# ...
427+
entity_managers:
428+
default:
429+
# ...
430+
dql:
431+
string_functions:
432+
test_string: Acme\HelloBundle\DQL\StringFunction
433+
second_string: Acme\HelloBundle\DQL\SecondStringFunction
434+
numeric_functions:
435+
test_numeric: Acme\HelloBundle\DQL\NumericFunction
436+
datetime_functions:
437+
test_datetime: Acme\HelloBundle\DQL\DatetimeFunction
438+
439+
However, if you are only using one entity manager, DQL functions can be registed like this:
440+
441+
.. code-block:: yaml
442+
doctrine:
443+
orm:
444+
# ...
445+
dql:
446+
string_functions:
447+
test_string: Acme\HelloBundle\DQL\StringFunction
448+
second_string: Acme\HelloBundle\DQL\SecondStringFunction
449+
numeric_functions:
450+
test_numeric: Acme\HelloBundle\DQL\NumericFunction
451+
datetime_functions:
452+
test_datetime: Acme\HelloBundle\DQL\DatetimeFunction

0 commit comments

Comments
 (0)