Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function search(Request $request, SearchService $searchService)
- {
- $message = $results = $totalResultCount = $maxPage = false;
- $langIso = $request->getLocale();
- $keywords = trim($request->query->get('keywords'));
- $page = $request->query->get('page', 1);
- $numericPage = preg_match('/^\d+$/', $page);
- if (!$keywords || $page < 1 || !$numericPage) {
- throw new NotFoundHttpException();
- }
- if (strlen($keywords) < 5) {
- $message = 'search.at.least.5.chars';
- }
- if (!$message) {
- [$results, $totalResultCount, $maxPage] = $searchService->getAll($keywords, $langIso, $page);
- }
- if (!$results) {
- $message = 'search.no.results';
- }
- if ($page > $maxPage && $maxPage != 0) {
- throw new NotFoundHttpException();
- }
- return $this->render('front/search/index.html.twig', [
- 'results' => $results,
- 'page' => $page,
- 'maxPage' => $maxPage,
- 'message' => $message
- ]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement