<?php
namespace App\Controller\Front;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Knp\Component\Pager\PaginatorInterface;
use App\Repository\Publication\PublicationRepository;
use App\Entity\Publication\Publication;
class PublicationController extends AbstractController
{
public function index(Request $request, PublicationRepository $repository, PaginatorInterface $paginator): Response
{
$keyword = $request->query->get('keyword');
$query = $repository->findPublicationsQuery($keyword);
$publications = $paginator->paginate($query, $request->query->getInt('page', 1), 3);
$recentPublications = $repository->findRecent();
return $this->render('front/publication/index.html.twig', [
'publications' => $publications,
'keyword' => $keyword,
'recentPublications' => $recentPublications,
]);
}
public function show(Publication $publication, PublicationRepository $repository): Response
{
$recentPublications = $repository->findRecent();
return $this->render('front/publication/show.html.twig', [
'publication' => $publication,
'recentPublications' => $recentPublications,
]);
}
}