From e399f79d2985b4b8bf5b7e8a2f741006c92b9950 Mon Sep 17 00:00:00 2001 From: flifloo Date: Sat, 16 Jan 2021 19:36:56 +0100 Subject: [PATCH] Refactor HomeController in PostController --- src/Controller/HomeController.php | 27 --------------------------- src/Controller/PostController.php | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 28 deletions(-) delete mode 100644 src/Controller/HomeController.php diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php deleted file mode 100644 index 9840c7f..0000000 --- a/src/Controller/HomeController.php +++ /dev/null @@ -1,27 +0,0 @@ -getDoctrine()->getRepository(Post::class); - return $this->render('home/index.html.twig', [ - 'controller_name' => 'HomeController', - 'posts' => $repo->getPublished($page*5, 5), - 'pages' => round(count($repo->getPublished())/5, 0, PHP_ROUND_HALF_UP)-1, - 'page' => $page - ]); - } -} diff --git a/src/Controller/PostController.php b/src/Controller/PostController.php index abff63e..34ea4e2 100644 --- a/src/Controller/PostController.php +++ b/src/Controller/PostController.php @@ -16,13 +16,29 @@ use Symfony\Component\String\Slugger\AsciiSlugger; class PostController extends AbstractController { + /** + * @Route("/{page}", name="home") + * @param int $page + * @return Response + */ + public function index(int $page = 0): Response + { + $repo = $this->getDoctrine()->getRepository(Post::class); + return $this->render('home/index.html.twig', [ + 'controller_name' => 'HomeController', + 'posts' => $repo->getPublished($page*5, 5), + 'pages' => round(count($repo->getPublished())/5, 0, PHP_ROUND_HALF_UP)-1, + 'page' => $page + ]); + } + /** * @Route("/post/{slug}", name="post") * @param Request $request * @param string $slug * @return Response */ - public function index(Request $request, string $slug): Response + public function post(Request $request, string $slug): Response { $post = $this->getDoctrine()->getRepository(Post::class)->findOneBy(array('slug' => $slug)); $form = $this->commentFormGenerator($post);