PHP code example of symfony / ux-pagination
1. Go to this page and download the library: Download symfony/ux-pagination library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
symfony / ux-pagination example snippets
// src/Controller/EventController.php
namespace App\Controller;
use App\Repository\EventRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\UX\Pagination\PaginatorInterface;
final class EventController extends AbstractController
{
#[Route('/events', name: 'event_index')]
public function __invoke(
EventRepository $events,
PaginatorInterface $paginator,
): Response {
$pagination = $paginator
->cursor($events->createQueryBuilder('event'))
->orderBy(['createdAt', 'id'], 'DESC')
->perPage(20)
->paginate();
return $this->render('event/index.html.twig', [
'pagination' => $pagination,
]);
}
}