Search code examples
symfonysymfony4pagerfanta

How do I add query params to pagerfanta paginator with symfony 4?


I'm using pagerfanta with symfony 4. I'm paginating DoctrineORM results with pagerfanta.

I want to paginate search results, without query params it's all working great :

{{ pagerfanta(articles, 'twitter_bootstrap4_translated', {routeName: 'articles_paginated'}) }}

I have urls looking like this :

http://host/articles/page/1

How do I add a param in the view so that the generated urls include some parameters, for example :

http://host/articles/published/1/page/1

Or :

http://host/articles/page/1?published=1

Solution

  • Use routeParams :

        {{ pagerfanta(articles, 'twitter_bootstrap4_translated', 
            {
                'routeName': 'articles_paginated',
                'routeParams': {},
            }
        ) }}