Skip to content

Commit 627d787

Browse files
committed
add documentation based on new changes
1 parent 1fffbf3 commit 627d787

File tree

4 files changed

+83
-21
lines changed

4 files changed

+83
-21
lines changed

Diff for: README.md

+27-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ older version of KnpPaginatorBundle - use **v1.0** tag in the repository
99

1010
## Latest updates
1111

12+
**2012-03-23**
13+
14+
- Changed the behavior of customization for query parameters. Etc. now there is no more **alias**
15+
for paginations. Instead it will use organized parameter names, which can be set for each pagination
16+
as different or configured in default global scope, see the [documentation](http://github.com/KnpLabs/KnpPaginatorBundle/blob/master/README.md#configuration)
17+
and [upgrade
18+
guide](http://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/doc/upgrade_to_2.2.md)
19+
20+
- If you do not wish to migrate to these new changes. Checkout paginator bundle at **v2.1** tag and
21+
komponents at **v1.0**
22+
1223
**2012-03-02**
1324

1425
- Added support for [Solarium](http://solarium-project.org), a PHP library that handles [Solr](http://lucene.apache.org/solr/) search.
@@ -44,7 +55,7 @@ Use the **v1.0** tag of KnpPaginatorBundle if you have to stay compatible with s
4455
- Separation of conserns, paginator is responsible for generating the pagination view only,
4556
pagination view - for representation purposes.
4657

47-
**Notice:** using multiple paginators requires setting the **alias** in order to keep non
58+
**Note:** using multiple paginators requires setting the **alias** in order to keep non
4859
conflicting parameters. Also it gets quite complicated with a twig template, since hash arrays cannot use
4960
variables as keys.
5061

@@ -77,25 +88,29 @@ Or if you use [composer](http://packagist.org)
7788

7889
{
7990
require: {
80-
"knplabs/knp-paginator-bundle": "*"
91+
"knplabs/knp-paginator-bundle": "dev-master"
8192
}
8293
}
8394

95+
<a name="configuration"></a>
96+
8497
### Configuration example
8598

86-
Is it not enough symfony2 configuration? You can override default templates using parameters
99+
You can configure default query parameter names and templates
87100

88101
``` yaml
89-
// File: app/configs/parameters.yml
90-
91-
parameters:
92-
knp_paginator.template.pagination: MyBundle:Pagination:pagination.html.twig
93-
knp_paginator.template.sortable: MyBundle:Pagination:sortable.html.twig
102+
knp_paginator:
103+
page_range: 5 # default page range used in pagination control
104+
default_options:
105+
page_name: page # page query parameter name
106+
sort_field_name: sort # sort field query parameter name
107+
sort_direction_name: direction # sort direction query parameter name
108+
distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements
109+
template:
110+
pagination: KnpPaginatorBundle:Pagination:sliding.html.twig # sliding pagination controls template
111+
sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template
94112
```
95113
96-
Or you can override default config values [this
97-
way](https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/doc/paginator_configuration.md)
98-
99114
### Add the namespaces to your autoloader unless you are using composer
100115
101116
``` php
@@ -182,3 +197,4 @@ return compact('pagination');
182197
[knp_component_pager]: https://github.com/KnpLabs/knp-components/blob/master/doc/pager/intro.md "Knp Pager component introduction"
183198
[doc_custom_pagination_subscriber]: https://github.com/KnpLabs/KnpPaginatorBundle/tree/master/Resources/doc/custom_pagination_subscribers.md "Custom pagination subscribers"
184199
[doc_templates]: https://github.com/KnpLabs/KnpPaginatorBundle/tree/master/Resources/doc/templates.md "Customizing Pagination templates"
200+

Diff for: Resources/doc/paginator_configuration.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ There's easy way to configure paginator - just add `knp_paginator` to `config.ym
44

55
## Default options
66

7-
knp_paginator:
8-
page_range: 5
9-
template:
10-
pagination: KnpPaginatorBundle:Pagination:sliding.html.twig
11-
sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig
7+
``` yaml
8+
knp_paginator:
9+
page_range: 5 # default page range used in pagination control
10+
default_options:
11+
page_name: page # page query parameter name
12+
sort_field_name: sort # sort field query parameter name
13+
sort_direction_name: direction # sort direction query parameter name
14+
distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements
15+
template:
16+
pagination: KnpPaginatorBundle:Pagination:sliding.html.twig # sliding pagination controls template
17+
sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template
18+
```
1219

Diff for: Resources/doc/templates.md

+29-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ There are few ways to override templates
1111
### Configuration
1212

1313
This way it will override it globally for all default pagination rendering.
14-
Place this parameter in **app/config/parameters.yml**
14+
15+
You can override templates in [configurion of
16+
paginator](http://github.com/KnpLabs/KnpPaginatorBundle/blob/master/README.md#configuration)
17+
18+
Or place this parameter in **app/config/parameters.yml**
1519

1620
knp_paginator.template.pagination: MyBundle:Pagination:pagination.html.twig
1721

@@ -73,13 +77,12 @@ This would set additional query parameter
7377

7478
### Additional pagination template parameters
7579

76-
If you need extra parameters in pagination template, use:
80+
If you need custom parameters in pagination template, use:
7781

7882
``` php
7983
<?php
80-
$pagination->setExtraViewParam('style', 'top');
81-
// or an array of extra parameters
82-
$pagination->setExtraViewParams(array(
84+
// set an array of custom parameters
85+
$pagination->setCustomParameters(array(
8386
'style' => 'bottom',
8487
'span_class' => 'whatever'
8588
));
@@ -100,3 +103,24 @@ In template:
100103
{% pagination.setPageRange(7) %}
101104
```
102105

106+
<a name="query-parameters"></a>
107+
108+
## Query parameters
109+
110+
If you need to change query parameters for paginator or use multiple paginators for the same page.
111+
You can customize these parameter names through [configuration](http://github.com/KnpLabs/KnpPaginatorBundle/blob/master/README.md#configuration)
112+
or manually with paginator options.
113+
114+
``` php
115+
<?php // controller
116+
117+
// will change "page" query parameter into "section" and sort direction "direction" into "dir"
118+
$paginator = $this->get('knp_paginator');
119+
$pagination = $paginator->paginate(
120+
$query, // target to paginate
121+
$this->get('request')->query->get('section', 1), // page parameter, now section
122+
10, // limit per page
123+
array('pageParameterName' => 'section', 'sortDirectionParameterName' => 'dir')
124+
);
125+
```
126+

Diff for: Resources/doc/upgrade_to_2.2.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Upgrade Paginator to 2.2 version
2+
3+
Changes to adapt to
4+
5+
- paginator option **alias** was removed, different names for query parameters can be set from now
6+
on see the [configuration options](http://github.com/KnpLabs/KnpPaginatorBundle/blob/master/README.md#configuration)
7+
and [changing query parameters](http://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/doc/templates.md#query-parameters) documentation
8+
- paginator option **whitelist** has changed to **sortFieldWhitelist**
9+
- regarding changes of query parameter handling, if you have extended pagination view, you will need
10+
to adapt query parameter name key usage, see [default
11+
template](http://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/views/Pagination/sliding.html.twig)
12+
13+
All these will help to use SEO friendly urls and makes it possible to inject translated parameter
14+
names into the paginator service as default options. Documentation on this part will be next in todo
15+
list.

0 commit comments

Comments
 (0)