Skip to content

Instantly share code, notes, and snippets.

@dupuchba
Created May 23, 2012 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dupuchba/2776253 to your computer and use it in GitHub Desktop.
Save dupuchba/2776253 to your computer and use it in GitHub Desktop.
symfony2 : search request
public function indexAction()
{
$form = $this->container->get('form.factory')->create(new CustomerSearchType());
$searchresult = '';
$keyword = '';
$request = $this->container->get('request');
$keyword = $request->request->get('customersearch_keyword');
if($keyword != '')
{
$em = $this->getDoctrine()->getEntityManager();
$repository = $this->getDoctrine()->getRepository('PiggyBoxTicketBundle:Customer');
$query = $repository->createQueryBuilder('p')
->where('a.firsname LIKE :keyword OR a.lastname LIKE :keyword')
->orderBy('a.nom', 'ASC')
->setParameter('keyword', '%'.$keyword.'%')
->getQuery();
$searchresult = $query->getResult();
}
else {
$searchresult = '[]';
}
$view = View::create();
$handler = $this->get('fos_rest.view_handler');
if ('html' === $this->getRequest()->getRequestFormat()){
$view->setData(array('form'=> $form));
}
else{
$view->setData($searchresult);
}
$view->setTemplate('PiggyBoxTicketBundle:Customer:index.html.twig');
return $view;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment