Doctrine2 building Where like expressions

Use case: You have a search form with multiple search criteria “name”, “id”, “type”, etc.

In your entity’s repository you would have a function like

Note, trying to use Gist for inline code, if it doesn’t work/render then go here https://gist.github.com/1039231

It’s important to note the setParameter call is responsible for wrapping the value in %’s and NOT the where expression itself. At the PDO driver layer, it either ignores or is aware of wrapped % symbology and allows those characters to get past the input scrubbers.

Minus the ->select expression, this could conceivably be portable to any and all Entities by shoving an application level EntityRepostory class between the individual entities and the Doctrine EntityRepository.