Skip to content

Commit

Permalink
Remove PaginationController interface and pass context instead. Refs b…
Browse files Browse the repository at this point in the history
  • Loading branch information
bsingr committed Oct 8, 2014
1 parent 0b3763c commit 262665f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
8 changes: 0 additions & 8 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
15 changes: 4 additions & 11 deletions utils/pagination/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion utils/pagination/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 262665f

Please sign in to comment.