SHARE
TWEET

Untitled

a guest Jun 27th, 2019 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function search(Request $request, SearchService $searchService)
  2.     {
  3.         $message = $results = $totalResultCount = $maxPage = false;
  4.         $langIso = $request->getLocale();
  5.         $keywords = trim($request->query->get('keywords'));
  6.         $page = $request->query->get('page', 1);
  7.         $numericPage = preg_match('/^\d+$/', $page);
  8.  
  9.  
  10.         if (!$keywords || $page < 1 || !$numericPage) {
  11.             throw new NotFoundHttpException();
  12.         }
  13.  
  14.         if (strlen($keywords) < 5) {
  15.             $message = 'search.at.least.5.chars';
  16.         }
  17.  
  18.         if (!$message) {
  19.             [$results, $totalResultCount, $maxPage] = $searchService->getAll($keywords, $langIso, $page);
  20.         }
  21.  
  22.         if (!$results) {
  23.             $message = 'search.no.results';
  24.         }
  25.  
  26.         if ($page > $maxPage && $maxPage != 0) {
  27.             throw new NotFoundHttpException();
  28.         }
  29.  
  30.         return $this->render('front/search/index.html.twig', [
  31.             'results' => $results,
  32.             'page' => $page,
  33.             'maxPage' => $maxPage,
  34.             'message' => $message
  35.         ]);
  36.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top