src/Controller/PostController.php line 27
<?phpnamespace Cms\Controller;use Cms\Entity\Post;use Cms\Repository\PostRepository;use Symfony\Bridge\Doctrine\Attribute\MapEntity;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\DependencyInjection\Attribute\Autowire;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;#[Route('/post')]class PostController extends AbstractController{private int $postPerPage;public function __construct(#[Autowire('%cms.post_per_page.public%')]int $postPerPage) {$this->postPerPage = $postPerPage;}#[Route('/{type<tags|category>}/{slug<[a-z-]+>}', name: 'cms_post_index', defaults: ['type' => '', 'slug' => ''], methods: ['GET'])]public function index(Request $request, string $type, string $slug, PostRepository $postRepository): Response{$criteria = ['deleted' => false, 'published' => true];if ($type !== '') {$criteria[$type] = $slug;}$posts = $postRepository->getPaginated($this->postPerPage, $criteria);if ($request->headers->get('Turbo-Frame') === 'frame_content') {return $this->render('post/index.frame.html.twig', ['posts' => $posts,]);}return $this->render('post/index.html.twig', ['posts' => $posts,]);}#[Route('/{slug}', name: 'cms_post_show', requirements: ['slug' => '[a-z0-9-]+'], methods: ['GET'])]public function show(Request $request, #[MapEntity(mapping: ['slug' => 'slug'])] Post $post): Response{if ($request->headers->get('Turbo-Frame') === 'frame_content') {return $this->render('post/show.frame.html.twig', ['post' => $post,]);}return $this->render('post/show.html.twig', ['post' => $post,]);}}