Controllers+JS: Change the blog search to a POST request

This commit is contained in:
Riyyi
2022-12-02 11:51:52 +01:00
parent 2ecc79c714
commit 0138a14c29
3 changed files with 16 additions and 17 deletions
+9 -15
View File
@@ -9,29 +9,23 @@ class BlogController extends PageController {
public function indexAction(): void
{
$archived = $this->router->request()->param('archived', 0);
$query = $this->router->request()->param('search', '');
$posts = $this->search($query, $archived);
$search = $this->router->request()->param('search', '');
$posts = $this->search($search, $archived);
$this->defineHelpers();
$this->router->service()->search = $query;
// AJAX search request will only render the posts partial
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->router->service()->partial($this->views . '/partials/blog-posts.php', ['posts' => $posts]);
return;
}
$this->router->service()->posts = $posts;
$this->router->service()->search = $search;
$this->router->service()->injectView = $this->views . '/partials/blog-posts.php';
parent::view('blog', 'Hello');
}
public function searchAction(): void
{
$archived = $this->router->request()->param('archived', 0);
$query = $this->router->request()->param('query', '');
$posts = $this->search($query, $archived);
$this->defineHelpers();
$this->router->service()->posts = $posts;
$this->router->service()->partial($this->views . '/partials/blog-posts.php', $posts);
}
//-------------------------------------//
private function search(string $query = '', int $archived = 0): ?array