-
Notifications
You must be signed in to change notification settings - Fork 26
/
doc.go
39 lines (39 loc) · 1.42 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Package pagination implements helper functions for request handlers
// which present results organized in numbered pages.
//
// This package can only be used with named handlers (registered via
// app.App.HandleNamed) and having patterns with no optional groups.
// (e.g. no "(something)?").
//
// Paging in this package assumes the following:
//
// - Pages start at 1.
// - The first page URL does not include the page number.
// - Other pages end with someprefix-<page-number>-somesuffix (see Pattern).
// - A URL with the page number set to 0 or 1 produces a redirect.
// - A URL with the page number > the available number of pages produces a 404.
//
// A typical handler using this package would look something like this.
//
// Registered as: App.HandleNamed("/popular/" + pagination.Pattern("", "/") + "$", PopularHandler, "popular")
//
// func PopularHandler(ctx *app.Context) {
// const itemsPerPage = 15
// q := ctx.Orm().Query(... some conditions ...)
// count := q.Table(o.NameTable("Item")).MustCount()
// p := pagination.New(ctx, int(count), itemsPerPage)
// if p == nil {
// // Request had an invalid page number and has been
// // already served
// return
// }
// var items []*Item
// p.Page(p.Page(), itemsPerPage).MustAll(&items)
// data := map[string]interface{}{
// "Items": items,
// "Page": p.Page(),
// "Paginator": p.Paginator(),
// }
// ctx.MustExecute("items.html", data)
// }
package pagination