adding redirections

pull/12/head
Aurian JAULT 10 months ago
parent 930b4518ee
commit 7b87376a57

@ -21,6 +21,7 @@ security:
login_path: app_login
check_path: app_login
enable_csrf: true
default_target_path: all post
logout:
path: app_logout
target: /login

@ -21,7 +21,7 @@ class PostController extends AbstractController
}
# DEBUG: Ne doit pas être laissé en production.
#[Route('/post/all', name: 'all post', methods: ['GET'])]
#[Route('/', name: 'all post', methods: ['GET'])]
public function getAllPost(): Response
{
$posts = $this->em->getRepository(Post::class)->findAll();
@ -52,6 +52,8 @@ class PostController extends AbstractController
#[Route('/post/new/', name: 'add_post', methods: ['GET', 'POST'])]
public function addPost(Request $request): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$post = new Post();
$form = $this->createForm(PostType::class, $post);
@ -65,8 +67,7 @@ class PostController extends AbstractController
$this->em->persist($post);
$this->em->flush();
return new Response($user->getUserIdentifier());
return $this->redirectToRoute('display post', ['id' => $post->getId()]);
}
return $this->render('post/new.html.twig', [

@ -1,5 +1,5 @@
<h1>All website posts</h1>
<a href="{{ path('add_post') }}" class="btn btn-primary">Créer un nouveau post</a>
{% for post in posts %}
<div>
<span>Id: {{ post.id }}</span>

Binary file not shown.
Loading…
Cancel
Save