func (this *Posts) Get() error { var user models.User if this.getUser(&user) { return nil } limit := 20 nums, _ := models.Count(&models.Post{UserId: user.Id}) pager := this.SetPaginator(limit, nums) var posts = make([]*models.Post, 0) models.Find(limit, pager.Offset(), &posts) this.Data["TheUserPosts"] = posts return this.Render("user/posts.html", this.Data) }
func (this *Comments) Get() error { var user models.User if this.getUser(&user) { return nil } limit := 20 nums, _ := models.CountCommentsByUserId(int64(user.Id)) pager := this.SetPaginator(limit, nums) var comments = make([]*models.Comment, 0) models.Find(limit, pager.Offset(), &comments) this.Data["TheUserComments"] = comments return this.Render("user/comments.html", this.Data) }
// query objects and set to template func (this *ModelAdminRouter) SetObjects(session *xorm.Session, objects interface{}) error { var app ModelFinder if a, ok := this.Ctx.Action().(ModelFinder); ok { app = a } cnt, err := session.Count(app.Object()) if err != nil { return err } // create paginator p := this.SetPaginator(20, cnt) if err := models.Find(p.PerPageNums, p.Offset(), objects); err != nil { return err } else { this.Data["Objects"] = objects this.Data["ObjectsCnt"] = cnt } return nil }