dev-master
9999999-devYet another Paginator bundle
MIT
The Requires
- php >=5.5.9
- doctrine/doctrine-bundle ^1.6
- doctrine/orm ^2.5
- symfony/http-foundation ^3.4
- twig/twig ^1.0||^2.0
by Leo
bundle symfony pagination paginator nadia nadia-lab
Yet another Paginator bundle
NadiaPaginatorBundle can help you build pagination UI quickly. You can design your filter and search UI with Symfony Form component, and easily validate input parameters with Form., (*1)
, (*2)
Install with composer , run:, (*3)
composer require nadialabs/paginator-bundle
// app/AppKernel.php public function registerBundles() { return array( // ... new Nadia\Bundle\PaginatorBundle\NadiaPaginatorBundle(), // ... ); }
nadia_paginator: default_options: input_key_class: Nadia\Bundle\PaginatorBundle\Input\InputKeys default_page_size: 10 default_page_range: 8 session_enabled: false default_translation_domain: null templates: pages: '@NadiaPaginator/templates/bootstrap4/pages.html.twig' searches: '@NadiaPaginator/templates/bootstrap4/searches.html.twig' filters: '@NadiaPaginator/templates/bootstrap4/filters.html.twig' sorts: '@NadiaPaginator/templates/bootstrap4/sorts.html.twig' sort_link: '@NadiaPaginator/templates/bootstrap4/sort_link.html.twig' page_sizes: '@NadiaPaginator/templates/bootstrap4/page_sizes.html.twig'
translation-domain
value for each Form.Define a Paginator configuration., (*4)
Example class: AppBundle\Paginator\Movies\PaginatorType
, (*5)
You can implement these methods to define a PaginatorType class:, (*6)
buildSearch
Use SearchBuilder
to setup search form elements with Symfony FormType styles., (*7)
buildFilter
Use FilterBuilder
to setup filter form elements with Symfony FormType styles., (*8)
buildSort
Use SortBuilder
to setup sorting methods., (*9)
buildPageSize
Use PageSizeBuilder
to setup page size list., (*10)
getFormOptions
Setup the paginator form options, return an array contain form options., (*11)
configureOptions
Setup the paginator options, you can define custom options to injecting extra data into PaginatorType. PaginatorType will use this options in these methods: buildSearch
buildFilter
buildSort
buildPageSize
getFormOptions
., (*12)
Define a QueryCompiler to build custom search criteria., (*13)
Example class for Doctrine QueryBuilder: AppBundle\Paginator\Movies\FilterQueryCompiler
, (*14)
Define a QueryCompiler to build custom filter criteria., (*15)
Example class for Doctrine QueryBuilder: AppBundle\Paginator\Movies\FilterQueryCompiler
, (*16)
Example controller: MovieController
Example entities: Movie
, People
, (*17)
To get a Pagination instance, the process as below:, (*18)
PaginatorTypeContainer
to generate a PaginatorType instance.PaginatorFactory
to generate a Paginator instance with a PaginatorType instance.// Example controller action $options = [ 'movieCompanies' => [ 'Warner Bros.', 'Sony Pictures', 'Walt Disney', 'Universal Pictures', '20th Century Fox', 'Paramount Pictures', 'Lionsgate Films', 'The Weinstein Company', 'DreamWorks Pictures', ], ]; $paginator = $this->get('nadia_paginator.paginator_factory')->create(PaginatorType::class, $options); $qb = $this->getDoctrine()->getRepository(Movie::class) ->createQueryBuilder('movie') ->select(['movie', 'director']) ->leftJoin('movie.director', 'director') ; /** @var Movie[]|Collection|Pagination $pagination */ $pagination = $paginator->paginate($qb);
You can easily render a list page with this template @NadiaPaginator/templates/bootstrap4/pagination.html.twig
Use twig embed
tag to overwrite tableContent
block and put your table contents in tableContent
block., (*19)
Example twig file: index.html.twig
, (*20)
// Render view $this->render('@App/Movie/index.html.twig', ['pagination' => $pagination]);
```twig {# Example view file #}, (*21)
{% use '@NadiaPaginator/templates/bootstrap4/pagination.html.twig' %}, (*22)
{% block tableContent %}, (*23)
{{ nadia_paginator_sort_link(pagination, 'title', 'movie.title', 'ASC') }} | {{ nadia_paginator_sort_link(pagination, 'description', 'movie.description', 'ASC') }} | {{ nadia_paginator_sort_link(pagination, 'releasedAt', 'movie.releasedAt', 'DESC') }} | Director | Company |
---|---|---|---|---|
{{ movie.title }} | {{ movie.description }} | {{ movie.releasedAt|date('Y-m-d') }} | {{ movie.director.name }} | {{ movie.company }} |
{% endblock tableContent %}, (*24)
### Rendering searches block in Twig Use `nadia_paginator_searches` method to render search block in Twig template. ```twig {{ nadia_paginator_searches(pagination, {attributes: {class: 'col-md-6 col-xl-4 search'}}) }}
Use nadia_paginator_filters
method to render filter block in Twig template., (*25)
{{ nadia_paginator_filters(pagination, {attributes: {class: 'col-md-4 col-xl-3 mb-1 filter'}}) }}
Use nadia_paginator_sorts
method to render sorting block in Twig template., (*26)
{{ nadia_paginator_sorts(pagination) }}
Use nadia_paginator_page_sizes
method to render page sizes block in Twig template., (*27)
{{ nadia_paginator_page_sizes(pagination) }}
{{ nadia_paginator_sort_link(pagination, 'title', 'movie.title', 'ASC') }}
Yet another Paginator bundle
MIT
bundle symfony pagination paginator nadia nadia-lab