Skip to content

Instantly share code, notes, and snippets.

@anvodev
Last active May 3, 2020 18:20
Show Gist options
  • Select an option

  • Save anvodev/c076ffc514b19c4b7e2ccf75718db559 to your computer and use it in GitHub Desktop.

Select an option

Save anvodev/c076ffc514b19c4b7e2ccf75718db559 to your computer and use it in GitHub Desktop.
get a post with or without comments
<?php
namespace App\Controller;
use App\Entity\Post;
use App\Review;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class PostController extends AbstractController
{
/**
* @Route("/post/{id}/{showComments}", name="post_show", methods={"GET"})
* @param Request $request
* @param Post $post
* @param Review $review
* @param bool $showComments
* @return Response
*/
public function show(Request $request, Post $post, Review $review, bool $showComments): Response
{
return $this->render('post/show.html.twig', [
'post' => $post,
'rating' => $review->getRating($post),
'comments' => $showComments ? $post->getComments() : null,
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment