76 search results for pagerfanta

Pagination with Pagerfanta

... They're called KnpPaginator and Pagerfanta. Both of these are really good... and I have a hard time choosing between them. In our Symfony 4 Doctrine tutorial, we talked about KnpPaginator. So in this tutorial, let's ...

6:20
Pagerfanta Pagination

To handle pagination, we're going to install the WhiteOctoberPagerfantaBundle. To install the bundle, run: Pagerfanta is a great library for pagination, whether you're doing things on the web or building an API. While ...

6:29
Pagination

... Though, I usually install another library that adds more features on top of those from Doctrine. Find your terminal and run: This installs a Pagerfanta bundle, which is a wrapper around a really nice library called ...

9:19
Themed Pagination Links

Pagerfanta is now controlling the query for this page and returning only the first 5 results. So... how do we get to page 2? How can we render some pagination links? Pagerfanta makes this delightfully easy. Scroll down ...

7:07
Upgrading to Symfony 6.0

... And... it fails! Hmm. One of the libraries I'm using is babdev/pagerfanta-bundle... and apparently it requires PHP 7.2... but we're using PHP 8. If you look further, there are some errors about pagerfanta-bundle[v2.8.0 ...

7:07
Pagination Column Sorting

Welcome to Day 13! We're going to tap the breaks on Stimulus and Turbo and only work with Symfony and Twig today. Our goal is to add pagination and column sorting to this list. I like to add pagination with Pagerfanta ...

8:04
// ... lines 1 - 5
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
// ... lines 8 - 10
class PaginationFactory
{
// ... lines 13 - 19
public function createCollection(QueryBuilder $qb, Request $request, $route, array $routeParams = array())
{
$page = $request->query->get('page', 1);
$adapter = new DoctrineORMAdapter($qb);
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage(10);
$pagerfanta->setCurrentPage($page);
$programmers = [];
foreach ($pagerfanta->getCurrentPageResults() as $result) {
$programmers[] = $result;
}
$paginatedCollection = new PaginatedCollection($programmers, $pagerfanta->getNbResults());
$createLinkUrl = function($targetPage) use ($route, $routeParams) {
return $this->router->generate($route, array_merge(
$routeParams,
array('page' => $targetPage)
));
};
$paginatedCollection->addLink('self', $createLinkUrl($page));
$paginatedCollection->addLink('first', $createLinkUrl(1));
$paginatedCollection->addLink('last', $createLinkUrl($pagerfanta->getNbPages()));
if ($pagerfanta->hasNextPage()) {
$paginatedCollection->addLink('next', $createLinkUrl($pagerfanta->getNextPage()));
}
if ($pagerfanta->hasPreviousPage()) {
$paginatedCollection->addLink('prev', $createLinkUrl($pagerfanta->getPreviousPage()));
}
return $paginatedCollection;
}
}
See Code Block in Script
Pagination Links

... standard thing to do: Copy this line and paste it twice. Name the second link first instead of self and point this to page 1. Name the third link last and have it generate a URL to the last page: $pagerfanta->getNbPages ...

4:47
// ... lines 1 - 10
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
// ... lines 13 - 20
class ProgrammerController extends BaseController
{
// ... lines 23 - 78
public function listAction(Request $request)
{
// ... lines 81 - 85
$adapter = new DoctrineORMAdapter($qb);
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage(10);
$pagerfanta->setCurrentPage($page);
// ... lines 90 - 102
}
// ... lines 104 - 202
}
See Code Block in Script
87 lines | src/Controller/QuestionController.php
// ... lines 1 - 9
use Pagerfanta\Doctrine\ORM\QueryAdapter;
use Pagerfanta\Pagerfanta;
// ... lines 12 - 17
class QuestionController extends AbstractController
{
// ... lines 20 - 32
public function homepage(QuestionRepository $repository)
{
$queryBuilder = $repository->createAskedOrderedByNewestQueryBuilder();
$pagerfanta = new Pagerfanta(new QueryAdapter($queryBuilder));
$pagerfanta->setMaxPerPage(5);
// ... lines 39 - 42
}
// ... lines 44 - 85
}
See Code Block in Script
57 lines | src/Controller/VinylController.php
// ... lines 1 - 5
use Pagerfanta\Doctrine\ORM\QueryAdapter;
use Pagerfanta\Pagerfanta;
// ... lines 8 - 12
class VinylController extends AbstractController
{
// ... lines 15 - 38
public function browse(VinylMixRepository $mixRepository, string $slug = null): Response
{
// ... lines 41 - 43
$adapter = new QueryAdapter($queryBuilder);
$pagerfanta = Pagerfanta::createForCurrentPageWithMaxPerPage(
$adapter,
1,
9
);
// ... lines 50 - 54
}
}
See Code Block in Script
87 lines | src/Controller/QuestionController.php
// ... lines 1 - 17
class QuestionController extends AbstractController
{
// ... lines 20 - 32
public function homepage(QuestionRepository $repository)
{
$queryBuilder = $repository->createAskedOrderedByNewestQueryBuilder();
$pagerfanta = new Pagerfanta(new QueryAdapter($queryBuilder));
$pagerfanta->setMaxPerPage(5);
return $this->render('question/homepage.html.twig', [
'pager' => $pagerfanta,
]);
}
// ... lines 44 - 85
}
See Code Block in Script
88 lines | src/Controller/QuestionController.php
// ... lines 1 - 17
class QuestionController extends AbstractController
{
// ... lines 20 - 32
public function homepage(QuestionRepository $repository, Request $request)
{
// ... lines 35 - 36
$pagerfanta = new Pagerfanta(new QueryAdapter($queryBuilder));
$pagerfanta->setMaxPerPage(5);
$pagerfanta->setCurrentPage($request->query->get('page', 1));
// ... lines 40 - 43
}
// ... lines 45 - 86
}
See Code Block in Script
36 lines | src/Controller/RecipeController.php
// ... lines 1 - 12
class RecipeController extends AbstractController
{
#[Route('/recipes/{page<\d+>}', name: 'app_recipes')]
public function recipes(RecipeRepository $recipeRepository, int $page = 1): Response
{
$queryBuilder = $recipeRepository->createQueryBuilderOrderedByNewest();
$adapter = new QueryAdapter($queryBuilder);
/** @var Recipe[]|Pagerfanta $pagerfanta */
$pagerfanta = Pagerfanta::createForCurrentPageWithMaxPerPage($adapter, $page, 4);
return $this->render('recipes/list.html.twig', [
'pager' => $pagerfanta,
]);
}
// ... lines 27 - 34
}
See Code Block in Script
97 lines | composer.json
{
// ... lines 2 - 4
"require": {
// ... lines 6 - 8
"babdev/pagerfanta-bundle": "^4.0",
// ... lines 10 - 13
"pagerfanta/doctrine-orm-adapter": "^4.0",
"pagerfanta/twig": "^4.0",
// ... lines 16 - 31
},
// ... lines 33 - 95
}
See Code Block in Script
39 lines | src/Controller/MainController.php
// ... lines 1 - 7
use Pagerfanta\Pagerfanta;
// ... lines 9 - 14
class MainController extends AbstractController
{
// ... line 17
public function homepage(
// ... lines 19 - 23
): Response
{
$pager = Pagerfanta::createForCurrentPageWithMaxPerPage(
// ... lines 27 - 29
);
// ... lines 31 - 36
}
}
See Code Block in Script
... update' will not do exactly the right thing!). I was stuck for a while getting pagerfanta to work but that's fine now. The docs for pagerfanta were a bit confusing because the link for the symfony framework on the ...
// ... lines 1 - 113
if ($pagerfanta->hasPreviousPage()) {
$paginatedCollection->addLink('prev', $createLinkUrl($pagerfanta->getPreviousPage()));
}
// ... lines 117 - 222
See Code Block in Script
// ... lines 1 - 110
if ($pagerfanta->hasNextPage()) {
$paginatedCollection->addLink('next', $createLinkUrl($pagerfanta->getNextPage()));
}
// ... lines 114 - 222
See Code Block in Script
Hey Gbd, It should be possible, why not? :) We were talking about Pagerfanta in this tutorial, in this specific chapter: https://symfonycasts.com/screencast/last-stack/pager-sorting - that's how to use Pagerfanta ...