I want to make a search functionality for my website with symfony. I did this form :
<div class="input-group" id="adv-search">
{{ form_start(form) }}
{{ form_widget(form.searchText,{'attr':{'id':'search_box','class':'search_box form-control ','placeholder':'Search'}}) }}
<div class="input-group-btn">
<div class="btn-group" role="group">
<button type="button" id="search_button" class="btn btn-search"><span
class="glyphicon glyphicon-search"
aria-hidden="true"></span></button>
</div>
</div>
{{ form_end(form) }}
</div>
Next I get what user write:
if ($form->isSubmitted()) {
$data = $form->getData();
$string = $data['searchText'];
echo '<pre>';
\Doctrine\Common\Util\Debug::dump($string);
exit;
echo '</pre>';
}
After I take what user wrote and I want to search in the table rows for that text and return an array in order to display it in twig. I was thinking about making a query builder,making a select but it didn't worked .
$this->getEntityManager()->createQuery('SELECT u FROM ParkResortBundle:Ad u
WHERE u. LIKE :string OR u.lastname LIKE :string')
->setParameter('string','%'.$string.'%')
->getResult();
}