mirror of
https://github.com/astaxie/beego.git
synced 2024-12-22 17:30:50 +00:00
Remove PaginationController interface and pass context instead. Refs #835.
This commit is contained in:
parent
0b3763cc67
commit
262665f4e5
@ -93,14 +93,6 @@ type ControllerInterface interface {
|
||||
URLMapping()
|
||||
}
|
||||
|
||||
func (c *Controller) GetCtx() *context.Context {
|
||||
return c.Ctx
|
||||
}
|
||||
|
||||
func (c *Controller) GetData() map[interface{}]interface{} {
|
||||
return c.Data
|
||||
}
|
||||
|
||||
// Init generates default values of controller operations.
|
||||
func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) {
|
||||
c.Layout = ""
|
||||
|
@ -18,16 +18,9 @@ import (
|
||||
"github.com/astaxie/beego/context"
|
||||
)
|
||||
|
||||
type PaginationController interface {
|
||||
GetCtx() *context.Context
|
||||
GetData() map[interface{}]interface{}
|
||||
}
|
||||
|
||||
// Instantiates a Paginator and assigns it to controller.Data["paginator"].
|
||||
func SetPaginator(controller PaginationController, per int, nums int64) (paginator *Paginator) {
|
||||
request := controller.GetCtx().Request
|
||||
paginator = NewPaginator(request, per, nums)
|
||||
data := controller.GetData()
|
||||
data["paginator"] = paginator
|
||||
// Instantiates a Paginator and assigns it to context.Input.Data["paginator"].
|
||||
func SetPaginator(context *context.Context, per int, nums int64) (paginator *Paginator) {
|
||||
paginator = NewPaginator(context.Request, per, nums)
|
||||
context.Input.Data["paginator"] = paginator
|
||||
return
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ In your beego.Controller:
|
||||
func (this *PostsController) ListAllPosts() {
|
||||
// sets this.Data["paginator"] with the current offset (from the url query param)
|
||||
postsPerPage := 20
|
||||
paginator := pagination.SetPaginator(this, postsPerPage, CountPosts())
|
||||
paginator := pagination.SetPaginator(this.Ctx, postsPerPage, CountPosts())
|
||||
|
||||
// fetch the next 20 posts
|
||||
this.Data["posts"] = ListPostsByOffsetAndLimit(paginator.Offset(), postsPerPage)
|
||||
|
Loading…
Reference in New Issue
Block a user