94 search results

// ... 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
// ... 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
// ... lines 1 - 110
if ($pagerfanta->hasNextPage()) {
$paginatedCollection->addLink('next', $createLinkUrl($pagerfanta->getNextPage()));
}
// ... lines 114 - 222
See Code Block in Script
// ... lines 1 - 113
if ($pagerfanta->hasPreviousPage()) {
$paginatedCollection->addLink('prev', $createLinkUrl($pagerfanta->getPreviousPage()));
}
// ... lines 117 - 222
See Code Block in Script
So I added a pagefrante to the example with LiveComponent as below: ```php // src/Twig/Components/SearchSite.php public function voyages() { if (!$this->query) { return []; } // return $this->voyageRepository->findBySearch($this->query, [], 10); $pager = Pagerfanta::createForCurrentPageWithMaxPerPage( new QueryAdapter( $this ->voyageRepository ->findBySearchQueryBuilder( $this->query, [], null ) ), $this…
Nataniel-Z
Nataniel-Z
Read Full Comment
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
111 lines | composer.json
{
// ... lines 2 - 5
"require": {
// ... lines 7 - 9
"babdev/pagerfanta-bundle": "^3.6",
// ... lines 11 - 45
},
// ... lines 47 - 109
}
See Code Block in Script
69 lines | src/Repository/StarshipRepository.php
// ... lines 1 - 14
class StarshipRepository extends ServiceEntityRepository
{
// ... lines 17 - 24
public function findIncompleteOrderedByDroidCount(): Pagerfanta
{
$query = $this->createQueryBuilder('s')
// ... line 28
->orderBy('COUNT(droid)', 'ASC')
->leftJoin('s.droids', 'droid')
->groupBy('s.id')
// ... lines 32 - 33
;
// ... lines 35 - 36
}
// ... lines 38 - 67
}
See Code Block in Script
69 lines | src/Repository/StarshipRepository.php
// ... lines 1 - 14
class StarshipRepository extends ServiceEntityRepository
{
// ... lines 17 - 24
public function findIncompleteOrderedByDroidCount(): Pagerfanta
{
$query = $this->createQueryBuilder('s')
// ... line 28
->orderBy('COUNT(starshipDroid)', 'ASC')
->leftJoin('s.starshipDroids', 'starshipDroid')
// ... lines 31 - 36
}
// ... lines 38 - 67
}
See Code Block in Script
67 lines | src/Repository/StarshipRepository.php
// ... lines 1 - 14
class StarshipRepository extends ServiceEntityRepository
{
// ... lines 17 - 24
public function findIncompleteOrderedByDroidCount(): Pagerfanta
{
// ... lines 27 - 34
}
// ... lines 36 - 65
}
See Code Block in Script
67 lines | src/Repository/StarshipRepository.php
// ... lines 1 - 14
class StarshipRepository extends ServiceEntityRepository
{
// ... lines 17 - 24
public function findIncomplete(): Pagerfanta
// ... lines 26 - 28
->orderBy('s.arrivedAt', 'DESC')
// ... lines 30 - 34
}
// ... lines 36 - 65
}
See Code Block in Script
67 lines | src/Repository/StarshipRepository.php
// ... lines 1 - 14
class StarshipRepository extends ServiceEntityRepository
{
// ... lines 17 - 24
public function findIncomplete(): Pagerfanta
// ... line 26
$query = $this->createQueryBuilder('s')
// ... lines 28 - 30
->getQuery()
;
// ... line 33
return new Pagerfanta(new QueryAdapter($query));
}
// ... lines 36 - 65
}
See Code Block in Script
I am curious why do you prefer pagerfanta over your own knp-pagination bundle? Is it a matter of taste or pagerfanta is more performance efficient? I personally find knp pagination bundle more flexible and easier to use.
Veselin-D
Veselin-D
Read Full Comment
In the last step, PagerFanta doesn't work. I only see one ship and 14 pages.
giorgiocba
giorgiocba
Read Full Comment
67 lines | src/Repository/StarshipRepository.php
// ... lines 1 - 14
class StarshipRepository extends ServiceEntityRepository
{
// ... lines 17 - 21
/**
* @return Starship[]
*/
public function findIncomplete(): Pagerfanta
{
// ... lines 27 - 34
}
// ... lines 36 - 65
}
See Code Block in Script
Ok, Pagerfanta will prepare a list of links (like ) but can normal links be used in Live Component? I tried and it throws me a MethodNotAllowedHttpException. Do I need to define something in Live Component, or convert links from Pagefranta to some butons/actions?
Nataniel-Z
Nataniel-Z
Read Full Comment
39 lines | src/Controller/MainController.php
// ... lines 1 - 14
class MainController extends AbstractController
{
// ... line 17
public function homepage(
// ... lines 19 - 23
): Response
{
$pager = Pagerfanta::createForCurrentPageWithMaxPerPage(
new QueryAdapter($voyageRepository->findBySearchQueryBuilder($query, $searchPlanets)),
$page,
10
);
return $this->render('main/homepage.html.twig', [
'voyages' => $pager,
// ... lines 34 - 35
]);
}
}
See Code Block in Script
Hi Victor, I followed the videos to the point where `{{ pagerfanta(pager) }}` was added to the template and then I did `composer require pagerfanta/twig`
Hi, is there a way to use PagerFanta in live components? I made a live component witch show a list of items with getItems method. I have a liveProp $query to filter the list. But if there are too many items the list will be…
52 lines | templates/vinyl/browse.html.twig
// ... lines 1 - 2
{% block body %}
// ... lines 4 - 26
<h2 class="mt-5">Mixes</h2>
<div class="row">
// ... lines 29 - 46
{{ pagerfanta(pager) }}
</div>
// ... lines 49 - 50
{% endblock %}
See Code Block in Script