Add Doctrine 2 User-Defined Functions

116 views
Skip to first unread message

Rico Leuthold

unread,
Mar 1, 2011, 5:21:20 AM3/1/11
to flextrine
Hi,

Since I have to work with dates a lot, I try to include the MySQL DQL
DATE_ADD function in Flextrine/Doctrine as showed on this page:
http://www.doctrine-project.org/blog/doctrine2-custom-dql-udfs

To start I created a DoctrineExtensions folder in the lib/ Directory
and placed the php classes within.

DateAdd.php snippet:

namespace DoctrineExtensions;

class DateAdd extends FunctionNode { ...

Then I added the function to the configuration in the
EntityManagerFactory:

// custom functions
$config->addCustomStringFunction('DATE_ADD', 'DoctrineExtensions/
DateAdd');

And finally registered the namespace in the bootstrap.php:

$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Flextrine' => __DIR__."/../lib",
'Doctrine' => __DIR__.'/../lib',
'Symfony' => __DIR__.'/../lib/Doctrine',
'DoctrineExtensions' => __DIR__.'/../lib',
));

But I keep getting 'PHP Fatal error: require() [..]' errors:

Failed opening required '[...]flextrine/app/micemeta/entities/
DoctrineExtensions/DateAdd.php'
[...]
in [...] flextrine/lib/Doctrine/Common/ClassLoader.php

It seems, that the class is searched using the $entityClassLoader
instead of $loader. Is there a relatively simple way to get this to
work?

I must admit, that I'm not a PHP guru, and these two class loaders are
really confusing me.

Many thanks
- rico

Dave Keen

unread,
Mar 1, 2011, 5:51:33 AM3/1/11
to flex...@googlegroups.com
Try putting a backlash before the DoctrineExtensions namespace in the add custom function call.
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Rico Leuthold

unread,
Mar 1, 2011, 6:03:47 AM3/1/11
to flex...@googlegroups.com
That's just platinum support ...

Thank you very much - rico

Reply all
Reply to author
Forward
0 new messages