From 164cc58efe9fc4cf41ad993631a08ea960cdf131 Mon Sep 17 00:00:00 2001 From: healdropper Date: Thu, 12 Jun 2014 12:25:45 +0200 Subject: [PATCH] Correct How to register custom DQL Functions For all symfony versions, official documentation suggests that custom dql functions should be declared in config.yml under doctrine.orm, but that's not correct. Actually, It works If your custom functions are declared inside every entity manager that uses them, i.e, doctrine.orm.entity_managers.default --- cookbook/doctrine/custom_dql_functions.rst | 59 +++++++++++++--------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/cookbook/doctrine/custom_dql_functions.rst b/cookbook/doctrine/custom_dql_functions.rst index 35141309b5e..25b2dd2ceca 100644 --- a/cookbook/doctrine/custom_dql_functions.rst +++ b/cookbook/doctrine/custom_dql_functions.rst @@ -17,14 +17,17 @@ In Symfony, you can register your custom DQL functions as follows: doctrine: orm: # ... - dql: - string_functions: - test_string: Acme\HelloBundle\DQL\StringFunction - second_string: Acme\HelloBundle\DQL\SecondStringFunction - numeric_functions: - test_numeric: Acme\HelloBundle\DQL\NumericFunction - datetime_functions: - test_datetime: Acme\HelloBundle\DQL\DatetimeFunction + entity_managers: + default: + # ... + dql: + string_functions: + test_string: Acme\HelloBundle\DQL\StringFunction + second_string: Acme\HelloBundle\DQL\SecondStringFunction + numeric_functions: + test_numeric: Acme\HelloBundle\DQL\NumericFunction + datetime_functions: + test_datetime: Acme\HelloBundle\DQL\DatetimeFunction .. code-block:: xml @@ -38,12 +41,15 @@ In Symfony, you can register your custom DQL functions as follows: - - Acme\HelloBundle\DQL\SecondStringFunction - Acme\HelloBundle\DQL\DatetimeFunction - + + + + Acme\HelloBundle\DQL\SecondStringFunction + Acme\HelloBundle\DQL\DatetimeFunction + + @@ -54,16 +60,21 @@ In Symfony, you can register your custom DQL functions as follows: $container->loadFromExtension('doctrine', array( 'orm' => array( // ... - 'dql' => array( - 'string_functions' => array( - 'test_string' => 'Acme\HelloBundle\DQL\StringFunction', - 'second_string' => 'Acme\HelloBundle\DQL\SecondStringFunction', - ), - 'numeric_functions' => array( - 'test_numeric' => 'Acme\HelloBundle\DQL\NumericFunction', - ), - 'datetime_functions' => array( - 'test_datetime' => 'Acme\HelloBundle\DQL\DatetimeFunction', + 'entity_managers' => array( + 'default' => array( + // ... + 'dql' => array( + 'string_functions' => array( + 'test_string' => 'Acme\HelloBundle\DQL\StringFunction', + 'second_string' => 'Acme\HelloBundle\DQL\SecondStringFunction', + ), + 'numeric_functions' => array( + 'test_numeric' => 'Acme\HelloBundle\DQL\NumericFunction', + ), + 'datetime_functions' => array( + 'test_datetime' => 'Acme\HelloBundle\DQL\DatetimeFunction', + ), + ), ), ), ),