ajout edit post
This commit is contained in:
@@ -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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
15
templates/post/edit.html.twig
Normal file
15
templates/post/edit.html.twig
Normal file
@@ -0,0 +1,15 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Edit Post{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Edit Post</h1>
|
||||
|
||||
{{ form_start(form) }}
|
||||
{{ form_widget(form) }}
|
||||
|
||||
<button type="submit" class="btn btn-primary">Save changes</button>
|
||||
{{ form_end(form) }}
|
||||
|
||||
<a href="{{ path('app_posts') }}" class="btn btn-secondary">Back to posts</a>
|
||||
{% endblock %}
|
Reference in New Issue
Block a user