Created
June 1, 2017 12:18
-
-
Save rileyrg/c172269a10ce78cf13a469cec6f61897 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function renderFilteredPersonList(Request $request, QueryBuilder $queryB, $resetRoute) | |
{ | |
$personForm = $this->createForm(PersonFilterType::class, null, [ | |
'method' => 'GET' | |
]); | |
$personForm->handleRequest($request); | |
if ($personForm->get('reset')->isClicked()) { | |
$personForm = $this->createForm(PersonFilterType::class, null, [ | |
'method' => 'GET' | |
]); | |
$request->query->remove($personForm->getName()); | |
$this->redirectToRoute($resetRoute); | |
} else { | |
if ($request->query->has($personForm->getName())) { | |
$qb_updater = $this->get('lexik_form_filter.query_builder_updater'); | |
// tell the query updater about the joins on the queryBuilder using setparts. no need for add_shared in the FilterType | |
$qb_updater->setParts(array( | |
'__root__' => 'p', | |
'p.adressData' => 'a', | |
'p.adminAdressData' => 'aa', | |
'p.eyeColor' => 'e' | |
)); | |
$qb_updater->addFilterConditions($personForm, $queryB); | |
} | |
} | |
$paginator = $this->get('knp_paginator'); | |
$pagination = $paginator->paginate( | |
$queryB, | |
$request->query->getInt('page', 1)/*page number*/, | |
5/*limit per page*/, | |
array('defaultSortFieldName' => 'p.surname', 'defaultSortDirection' => 'asc') | |
); | |
// parameters to template | |
return $this->render( | |
'person/person.list.html.twig', | |
array( | |
'personForm' => $personForm->createView(), | |
'pagination' => $pagination | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment