// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^3.7", // v3.7.0
"doctrine/doctrine-bundle": "^2.7", // 2.7.0
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.2
"doctrine/orm": "^2.12", // 2.12.3
"knplabs/knp-time-bundle": "^1.18", // v1.19.0
"pagerfanta/doctrine-orm-adapter": "^3.6", // v3.6.1
"pagerfanta/twig": "^3.6", // v3.6.1
"sensio/framework-extra-bundle": "^6.2", // v6.2.6
"stof/doctrine-extensions-bundle": "^1.7", // v1.7.0
"symfony/asset": "6.1.*", // v6.1.0
"symfony/console": "6.1.*", // v6.1.2
"symfony/dotenv": "6.1.*", // v6.1.0
"symfony/flex": "^2", // v2.4.5
"symfony/framework-bundle": "6.1.*", // v6.1.2
"symfony/http-client": "6.1.*", // v6.1.2
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/proxy-manager-bridge": "6.1.*", // v6.1.0
"symfony/runtime": "6.4.3", // v6.4.3
"symfony/twig-bundle": "6.1.*", // v6.1.1
"symfony/ux-turbo": "^2.0", // v2.3.0
"symfony/webpack-encore-bundle": "^1.13", // v1.15.1
"symfony/yaml": "6.1.*", // v6.1.2
"twig/extra-bundle": "^2.12|^3.0", // v3.4.0
"twig/twig": "^2.12|^3.0" // v3.4.1
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.2
"symfony/debug-bundle": "6.1.*", // v6.1.0
"symfony/maker-bundle": "^1.41", // v1.44.0
"symfony/stopwatch": "6.1.*", // v6.1.0
"symfony/web-profiler-bundle": "6.1.*", // v6.1.2
"zenstruck/foundry": "^1.21" // v1.21.0
}
}
17 Comments
Hello !
How can we add custom CSS to the pagination links, or customize the bootstrap CSS ?
Hey AntoineR,
There's an official way to override templates from third-party bundles in Symfony, check the docs: https://symfony.com/doc/current/bundles/override.html#templates
That's the most flexibly way to modify templates as you need. Another (probably easier) solution would be to check bundle's docs, probably they have flexibly configuration. For example, they allow you to choose ready-to-use templates among which there's a bootstrap template with correct classes, see: https://www.babdev.com/open-source/packages/pagerfanta/docs/3.x/views
Cheers!
Thank you very much !
Hey SymfonyCast:
My Windows 10 machine was hit with the dreaded OS_BOOT_FAILURE resulting in the loss of a lot of my data. All my files and folders I used for this mixed_vinyl tutorial were stored inside V.S. Code's file explorer and wiped clean. My mixed_vinyl tutorial was stored in a mixed_vinyl_tutorial Github repo I created. As a result of the OS_BOOT_FAILURE, I lost my administrative access privileges to my mixed_vinyl_tutorial repo. I tried cloning my repo, but discovered I don't have my original administrative rights and privileges as the owner of the repo would have. I was wondering if SynfonyCast would be able to help me figure this out. Is there a way for me get my administrative privileges back without having to start over from the beginning or creating a new repository? Can I transfer all the code that I stored in my Github repo back to my V.S. Code file explorer and regain ownership of my original administrative privileges? This would be a lifesaver for me and would save me a lot of time! if you have more questions please contact me via this thread or email thanks!
Hey Akili,
I'm sorry to hear you lost your data! That's the worst :/ Unfortunately, the SymfonyCasts support team does not have the bandwidth to solve customer's personal project issues. Moreover, we don't have specialists who could help you with such tasks, unfortunately. Most of our developers are using Mac/Linux OS. You probably need to find a recovery data company locally that would help with it, you would need to bring your physical HDD there I suppose. If you had some backups on GitHub but you lost access to it now - I think you need to contact GitHub support directly to ask about some ways to recover, I think they may help you with it too.
I hope that helps!
Cheers!
@Victor :
Thank you for your timely response Victor. communicating with githubs support team will be too much of a rabbit hole to crawl through :/ I don't want to waste more time than I already have. It looks like I have not other choice but to revisit the whole course a second time. I'll look at it as a refresher course.
Hey Akili,
Well, re-watching the course is always a good idea as it will help you to remember the material better, and probably you will notice some minor details you have missed in the first tun.
Unless you lost some important unique data that you need to recover - you can totally ignore learning course projects, not a big deal probably.
Cheers!
Thanks for this awesome tutorial. I am wondering if there is any way to adapte Pagerfanta with Twig orders. (I know how to custmize it by QueryBuilder)
For example:
Let's say I need to use "If statements" like this:
In this case, Twig still counts the non-published activities, it only hides it.
Many thanks in advance!
Hi @Lubna!
Interesting! You want to hide certain results, but still want them to be counted in the total item count and also in the pagination? What I mean is, if you are showing 10 items per page, and there are 100 items, but only 50 are published, you would still want Pagerfanta to show 10 pages. Is that correct?
If so, I might be missing some detail. The code you showed above looks great, of course: you are able to loop over the 10 items on the page and use an if statement to hide (for example) 5 of them. Then, naturally, when you use pagerfanta, it will not know about this, so it will still think there are 10 pages. I'm guessing this isn't quite what you want - but let me know - I'm missing a piece to your requirement!
Sorry I couldn't be more immediately helpful - but let me know what detail I'm missing :).
Cheers!
Thanks @weaverryan for your reply and appreciate your time!
Not exactly, when I'm showing 10 items per page, and there are 100 items, but only 50 are published, Pagerfanta still show 10 pages.
Seems there is no solution, because Pagerfanta can't control the data reicieved of QuieryBuilder.
Have a nice day :)
Hi @Lubna!
I understand! Yes, the solution for this would always need to be to "go back and modify the original query" - which I know you were already aware of :).
Good luck!
Hey there,
I have on single page two lists of items (for example active and archive messages). I need to have pagination for both of lists. But the parameter page is in collision with each other.
How I can specify for each pagerfanta name of parameter for pagination? For example to have activePage parameter for active messages parameter and archivePage for archived messages? So URL should be .../messages/list?activePage=2&archivePage=4 - this means that active messages are at page 2 and archive messages are at page 4.
Thanks everyone for advices.
Cheers!
Hey skocdopolet!
That's an excellent question! Here's how to do this, on your template:
Ref: bottom of https://www.babdev.com/open-source/packages/pagerfantabundle/docs/3.x/rendering-pagerfantas
Then, of course, you'll read
$request->query->get('activePage')in your controller when fetching the current page.I hope this helps!
Hey weaverryan!
Thank you for your reply. Its worked for me very well!
I have another question. Is it possible to omit prev and next links while rendering pagerfanta? I need only the page numbers...
I am searching in the documentation and I was try to inspect source code too, but I was not successfull.
I solve this requirement by CSS and display:none, but I am searching better solution.
Cheers!
Hey skocdopolet!
Yea... interesting question. As best I can see, this is not supported by a simple option. Instead, I think you'll need to override the pagination template. So, for example, in this tutorial we're using the
@BabDevPagerfanta/twitter_bootstrap5.html.twigtemplate, which should be this one: https://github.com/BabDev/Pagerfanta/blob/3.x/lib/Twig/templates/twitter_bootstrap5.html.twig... which really just extends this one: https://github.com/BabDev/Pagerfanta/blob/3.x/lib/Twig/templates/twitter_bootstrap4.html.twigAnyways, I believe if you just copied that template into your code, customized it, then updated the pagerfanta config to point at it, you'd be in business. Specifically, you would override all of the
previous_page_linkandnext_page_linkblocks (including thedisabledversions) and render nothing.I'd love to know if this works, so let me know if you have a chance to try it!
Cheers!
You can use
($page = intval($request->query->get('page', 1))) > 0 ? $page : 1to make sure that page always an integer otherwise the first page. Because the type for the parameter$currentPage(the second argument) is set to int and it'll break your code and throw 500.Hey there,
Yes, is a good idea to make sure that you get an int out of the request param, and there's a new fancy way to do that in a modern Symfony app
$request->query->getInt('page', 1);Cheers!
"Houston: no signs of life"
Start the conversation!