mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:00:54 +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()
|
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.
|
// Init generates default values of controller operations.
|
||||||
func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) {
|
func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) {
|
||||||
c.Layout = ""
|
c.Layout = ""
|
||||||
|
@ -18,16 +18,9 @@ import (
|
|||||||
"github.com/astaxie/beego/context"
|
"github.com/astaxie/beego/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PaginationController interface {
|
// Instantiates a Paginator and assigns it to context.Input.Data["paginator"].
|
||||||
GetCtx() *context.Context
|
func SetPaginator(context *context.Context, per int, nums int64) (paginator *Paginator) {
|
||||||
GetData() map[interface{}]interface{}
|
paginator = NewPaginator(context.Request, per, nums)
|
||||||
}
|
context.Input.Data["paginator"] = paginator
|
||||||
|
|
||||||
// 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
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ In your beego.Controller:
|
|||||||
func (this *PostsController) ListAllPosts() {
|
func (this *PostsController) ListAllPosts() {
|
||||||
// sets this.Data["paginator"] with the current offset (from the url query param)
|
// sets this.Data["paginator"] with the current offset (from the url query param)
|
||||||
postsPerPage := 20
|
postsPerPage := 20
|
||||||
paginator := pagination.SetPaginator(this, postsPerPage, CountPosts())
|
paginator := pagination.SetPaginator(this.Ctx, postsPerPage, CountPosts())
|
||||||
|
|
||||||
// fetch the next 20 posts
|
// fetch the next 20 posts
|
||||||
this.Data["posts"] = ListPostsByOffsetAndLimit(paginator.Offset(), postsPerPage)
|
this.Data["posts"] = ListPostsByOffsetAndLimit(paginator.Offset(), postsPerPage)
|
||||||
|
Loading…
Reference in New Issue
Block a user