1

I have created a user defined function for Doctrine ORM inside my Symfony2 application, called isnull_string(). This is to be able to execute a query that would place null records at the bottom instead of the top, when ordering by ascending order on a string field. In MySQL it would look something like SELECT * FROM airlines ORDER BY ISNULL(name), name;

The function is registered in the global config.yml file, as instructed in the Symfony2 docs. But nowhere can I find any resources as how I could use this function inside the creation of a QueryBuilder object.

Here is what I'm doing to create my drop down menu:

 $builder->add('airline', 'entity', array('query_builder' 
       => function(EntityRepository $er){
              return $er->createQueryBuilder('airline')->orderBy('isnull_string(airline.name), airline.name', 'ASC');
          });

But it's returning a syntax error: Expected end of string, got '('

So how can I use this custom function inside the FormBuilderInterface?

4

0 回答 0