Last active
May 3, 2020 18:20
-
-
Save anvodev/c076ffc514b19c4b7e2ccf75718db559 to your computer and use it in GitHub Desktop.
get a post with or without comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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