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);