2016-04-29

I've built a page in Symfony, which utilises the Doctrine Query Builder to return results. The page also integrates search functionality. The page works fine at the minute, but I'm wondering if the Doctrine Query Builder section of my code can be re-factored?

So my question is, rather than copying and pasting the same query (as I have done so below in my code ($results)) and adding additional 'where' and 'setParameter' methods to the query builder, is it possible to just append the additional options to the first query so that I don't have to re-use code?

So an example of what I'm looking for/trying to get at would be like the following:

I've no idea if its possible to extend the query I've previously built and Googling for hours on end doesn't seem to return any useful sources I can relate to.

I've also looked through plenty of Doctrine documentation, including the following without success: http://www.doctrine-project.org/api/orm/2.2/class-Doctrine.ORM.QueryBuilder.html

Thanks in advance

Show more