diff options
author | Thomas Lange <code@nerdmind.de> | 2021-07-22 21:17:57 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2021-07-22 21:17:57 +0200 |
commit | 0db1beaea6b849790aa0f1f4ecbf6439ce4f1104 (patch) | |
tree | e4fb555253891bbf8b192cd7ab5fd28cd7ef914c /admin/page | |
parent | cb9097e0199cf6afca3f144edb7d7addaec1cb59 (diff) | |
download | blog-0db1beaea6b849790aa0f1f4ecbf6439ce4f1104.tar.gz blog-0db1beaea6b849790aa0f1f4ecbf6439ce4f1104.tar.xz blog-0db1beaea6b849790aa0f1f4ecbf6439ce4f1104.zip |
Catch possible PDOException for search request
Catch possible PDOException on search requests with queries like "*" and
pass the exception message to the template for displaying.
Diffstat (limited to 'admin/page')
-rw-r--r-- | admin/page/search.php | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/admin/page/search.php b/admin/page/search.php index 85448df..a88ab15 100644 --- a/admin/page/search.php +++ b/admin/page/search.php @@ -30,9 +30,13 @@ $offset = ($currentSite-1) * $site_size; # Check for search request #=============================================================================== if($search = HTTP::GET('q')) { - foreach($PageRepository->search($search, [], $site_size, $offset) as $Page) { - $User = $UserRepository->find($Page->get('user')); - $templates[] = generatePageItemTemplate($Page, $User); + try { + foreach($PageRepository->search($search, [], $site_size, $offset) as $Page) { + $User = $UserRepository->find($Page->get('user')); + $templates[] = generatePageItemTemplate($Page, $User); + } + } catch(PDOException $Exception) { + $messages[] = $Exception->getMessage(); } } @@ -57,6 +61,9 @@ if($count = $PageRepository->getLastSearchOverallCount()) { $SearchTemplate = Template\Factory::build('page/search'); $SearchTemplate->set('QUERY', $search); $SearchTemplate->set('PAGES', $templates ?? []); +$SearchTemplate->set('FORM', [ + 'INFO' => $messages ?? [] +]); $SearchTemplate->set('PAGINATION', $pagination_data ?? []); $MainTemplate = Template\Factory::build('main'); |