title: Complex Doctrine2 queries with optional parameters
body: <p>Wondering the best way to go about querying the database with optional parameters. For example, I have a search which has name, location, price, sort by * etc</p>
  
  <p>What should I do on the model and controller level on an application (I'm using Symfony2 btw)?</p>
  
  <p>My thought was to dynamically build the DQL in the model, and pass serialized parameters to that via the controller like:</p>
  
  <pre><code>#controller
  
  $res = $repo-&gt;search($serializedData);
  
  #model/repo-&gt;search()
  
  $data = expand($serializedData);
  $dql = '';
  
  if($data['sortby'])
    $dql .= .....
  </code></pre>
  
  <p>Any advice?</p>
  
  <p>This code is for demonstration purposes. It is not in the slight bit valid :)</p>