262665f4 by Jens Bissinger

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

1 parent 0b3763cc
...@@ -93,14 +93,6 @@ type ControllerInterface interface { ...@@ -93,14 +93,6 @@ type ControllerInterface interface {
93 URLMapping() 93 URLMapping()
94 } 94 }
95 95
96 func (c *Controller) GetCtx() *context.Context {
97 return c.Ctx
98 }
99
100 func (c *Controller) GetData() map[interface{}]interface{} {
101 return c.Data
102 }
103
104 // Init generates default values of controller operations. 96 // Init generates default values of controller operations.
105 func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) { 97 func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{}) {
106 c.Layout = "" 98 c.Layout = ""
......
...@@ -18,16 +18,9 @@ import ( ...@@ -18,16 +18,9 @@ import (
18 "github.com/astaxie/beego/context" 18 "github.com/astaxie/beego/context"
19 ) 19 )
20 20
21 type PaginationController interface { 21 // Instantiates a Paginator and assigns it to context.Input.Data["paginator"].
22 GetCtx() *context.Context 22 func SetPaginator(context *context.Context, per int, nums int64) (paginator *Paginator) {
23 GetData() map[interface{}]interface{} 23 paginator = NewPaginator(context.Request, per, nums)
24 } 24 context.Input.Data["paginator"] = paginator
25
26 // Instantiates a Paginator and assigns it to controller.Data["paginator"].
27 func SetPaginator(controller PaginationController, per int, nums int64) (paginator *Paginator) {
28 request := controller.GetCtx().Request
29 paginator = NewPaginator(request, per, nums)
30 data := controller.GetData()
31 data["paginator"] = paginator
32 return 25 return
33 } 26 }
......
...@@ -18,7 +18,7 @@ In your beego.Controller: ...@@ -18,7 +18,7 @@ In your beego.Controller:
18 func (this *PostsController) ListAllPosts() { 18 func (this *PostsController) ListAllPosts() {
19 // sets this.Data["paginator"] with the current offset (from the url query param) 19 // sets this.Data["paginator"] with the current offset (from the url query param)
20 postsPerPage := 20 20 postsPerPage := 20
21 paginator := pagination.SetPaginator(this, postsPerPage, CountPosts()) 21 paginator := pagination.SetPaginator(this.Ctx, postsPerPage, CountPosts())
22 22
23 // fetch the next 20 posts 23 // fetch the next 20 posts
24 this.Data["posts"] = ListPostsByOffsetAndLimit(paginator.Offset(), postsPerPage) 24 this.Data["posts"] = ListPostsByOffsetAndLimit(paginator.Offset(), postsPerPage)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!