1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 07:30:55 +00:00

Remove PaginationController interface and pass context instead. Refs #835.

This commit is contained in:
Jens Bissinger 2014-10-08 15:59:26 +02:00
parent 0b3763cc67
commit 262665f4e5
3 changed files with 5 additions and 20 deletions

View File

@ -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 = ""

View File

@ -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
}

View File

@ -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)