From 86f4accd78db1a0a0b620a5b180d279fb12897a9 Mon Sep 17 00:00:00 2001 From: flifloo Date: Sun, 17 Jan 2021 16:24:46 +0100 Subject: [PATCH] not found on wrong post in main page --- src/Controller/PostController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Controller/PostController.php b/src/Controller/PostController.php index fe37aba..834391a 100644 --- a/src/Controller/PostController.php +++ b/src/Controller/PostController.php @@ -45,6 +45,9 @@ class PostController extends AbstractController public function post(Request $request, string $slug): Response { $post = $this->getDoctrine()->getRepository(Post::class)->findOneBy(array('slug' => $slug)); + if (!$post) { + throw $this->createNotFoundException("Post not found"); + } $form = $this->commentFormGenerator($post); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) {