27 lines
814 B
PHP
27 lines
814 B
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\Post;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
class HomeController extends AbstractController
|
|
{
|
|
/**
|
|
* @Route("/{page}", name="home")
|
|
* @param int $page
|
|
* @return Response
|
|
*/
|
|
public function index(int $page = 0): Response
|
|
{
|
|
$repo = $this->getDoctrine()->getRepository(Post::class);
|
|
return $this->render('home/index.html.twig', [
|
|
'controller_name' => 'HomeController',
|
|
'posts' => $repo->findBy(array(), array('publishedAt' => 'DESC'), 5, $page*5),
|
|
'pages' => round($repo->count(array())/5, 0, PHP_ROUND_HALF_UP),
|
|
'page' => $page
|
|
]);
|
|
}
|
|
}
|