diff --git a/src/Controller/PostController.php b/src/Controller/PostController.php index b0bc747..a6320a9 100644 --- a/src/Controller/PostController.php +++ b/src/Controller/PostController.php @@ -47,4 +47,22 @@ class PostController extends AbstractController 'form' => $form, //->createView(), ]); } + + #[Route('/posts/edit/{id}', name: 'app_edit_post')] + #[IsGranted('ROLE_USER', message: 'You must be logged in to access this page.')] + public function edit(Request $request, EntityManagerInterface $entityManager, Post $post): Response +{ + $form = $this->createForm(PostType::class, $post); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $entityManager->flush(); + + return $this->redirectToRoute('app_posts'); + } + + return $this->render('post/edit.html.twig', [ + 'form' => $form->createView(), + ]); +} } diff --git a/templates/post/edit.html.twig b/templates/post/edit.html.twig new file mode 100644 index 0000000..1c8e0bb --- /dev/null +++ b/templates/post/edit.html.twig @@ -0,0 +1,15 @@ +{% extends 'base.html.twig' %} + +{% block title %}Edit Post{% endblock %} + +{% block body %} +