adding redirections

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

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

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

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

Binary file not shown.
Loading…
Cancel
Save