title: How to do If statement in symfony2 correctly in the controller
body: <p>Can you help me on how to do this correctly.</p>
  
  <p>Below is my  DefaultController.</p>
  
  <pre><code>public function searchAction(){     
  $request = $this-&gt;getRequest();
  $data = $request-&gt;request-&gt;get('search');
  $data1 = $request-&gt;request-&gt;get('search1');
  $data2 = $request-&gt;request-&gt;get('search2');
  
  
  $em = $this-&gt;getDoctrine()-&gt;getManager();
  $query = $em-&gt;createQuery(
   'SELECT p 
   FROM FooTransBundle:Trans p, FooTransBundle:Supplier d
   WHERE p.transType LIKE :data
   OR d.name LIKE :data1
   OR p.sendDate LIKE :data2')
  -&gt;setParameter('data',$data)
  -&gt;setParameter('data1', $data1)
  -&gt;setParameter('data2',$data2);  
  
  $res = $query-&gt;getResult();
  return $this-&gt;render('FooTransBundle:Default:search.html.twig', array(
  'res' =&gt; $res));
  }
  </code></pre>
  
  <p>And below is my twig file.</p>
  
  <pre><code>&lt;form class="form-horizontal"role="form"name ="search"method="post" action="{{path('foo_trans_search') }}"&gt;
   &lt;div class="form-group"&gt;
    &lt;label for="agr"class="col-sm-2 control-label"&gt;Trans Type&lt;/label&gt;
      &lt;div class="col-sm-10"&gt;
          &lt;input type="text"class="form-control"id="agr"placeholder="Trans Type" name ="search"&gt;
      &lt;/div&gt;
     &lt;/div&gt;
     &lt;div class="form-group"&gt;
        &lt;label for="trad"class="col-sm-2 control-label"&gt;Name:&lt;/label&gt;
         &lt;div class="col-sm-10"&gt;
           &lt;input type="text"class="form-control"id="trad"placeholder="Name" name ="search1"&gt;
         &lt;/div&gt;
     &lt;/div&gt;
    &lt;div class="form-group"&gt;
       &lt;label for="send"class="col-sm-2 control-label"&gt;Send Date:&lt;/label&gt;
        &lt;div class="col-sm-10"&gt;
         &lt;input type="text"class="form-control"id="send"placeholder="YYYY-MM-DD"name ="search2"&gt;
       &lt;/div&gt;
      &lt;/div&gt;
     &lt;div class="form-group"&gt;
         &lt;div class="col-sm-offset-2 col-sm-10"&gt;
               &lt;button type="submit"class="btn btn-primary"&gt;Submit&lt;/button&gt;
              &lt;a class="btn btn-primary"href="{{  path('foo_trans_show_all')}}"role="button"target="iframe_loader"&gt;Cancel&lt;/a&gt;
           &lt;/div&gt;
  &lt;/div&gt;
    &lt;/form&gt;
          &lt;table class="table table-condensed"&gt;
           &lt;tr class="active "&gt;
             &lt;td&gt;Supplier Name&lt;/td&gt;
              &lt;td&gt;Trans Type&lt;/td&gt;
              &lt;td&gt;Transaction Date&lt;/td&gt;  
           &lt;/tr&gt;
            &lt;tr class="info"&gt;
              {% block content_header_more %}
  
                  {% for new in res %}
                     &lt;td&gt;&lt;a href="{{ path('foo_trans_show', {'id':  new.transId  }) }}"&gt;{{ new.getSupplier.name }}&lt;/a&gt;
                    &lt;td&gt;{{new.transactionType}}&lt;/td&gt;
                    &lt;td&gt;{{new.sendDate}}&lt;/td&gt;           
          &lt;/tr&gt; 
            {% endfor %}
        {% endblock %}
   &lt;/table&gt;
  </code></pre>
  
  <p>Can you help me doing an if statement in my code. What I really want is something like this. I have three input fields as shown in my twig file, and I want that my it will still search based on the data being inputted. Example situation:</p>
  
  <pre><code>if($data != null &amp;&amp; $data1 != null &amp;&amp; $data2 != null){
  
  //query that will search for the three values
  }
  </code></pre>
  
  <p>Then it will query the for the 3 data that matches that words. And if it was all null it will return something that say "Nothing to search". And also even if the user will only put data in the two input fields, it will still do it's purpose. Example situation of if again:</p>
  
  <pre><code> if($data == null &amp;&amp; $data1 != null &amp;&amp; $data2 != null){
  //query here that will search the two values that are not null
   }
  </code></pre>
  
  <p>Please can you help me. Any idea?? Thanks in advance.</p>