func (this *Home) Index() { this.TplNames = "home.html" this.Data["Title"] = "首页" currentPage := 1 //获取上一页的页码 if page, err := strconv.Atoi(this.Input().Get("p")); err == nil { currentPage = page } articleList, count := article.GetAllArticles(pageLimit, currentPage) pagination.SetPaginator(this.Ctx, pageLimit, count) this.Data["topicList"] = articleList this.Data["categoryList"] = article.GetCategories(false) }
//修改文章 文章id func (this *Article) ModifyArticle() { if this.Ctx.Request.Method == "GET" { this.TplNames = "modify_article.html" articleIdStr := this.Input().Get("id") if articleIdStr == "" { this.Redirect("articleList", 302) return } articleRes, err := article.GetArticleById(articleIdStr) if err != nil { this.Redirect("articleList", 302) return } this.Data["articleId"] = articleIdStr this.Data["categories"] = article.GetCategories(true) this.Data["Title"] = articleRes.Title this.Data["Tags"] = articleRes.Tags this.Data["Content"] = articleRes.Content this.Data["Id"] = articleRes.Category.Id } else { articleId := this.GetString("articleId") isDraft, _ := strconv.ParseBool(this.Input().Get("isDraft")) topicTitle := this.GetString("articleTitle") content := this.GetString("content") categoryId, _ := strconv.Atoi(this.GetString("categoryId")) articleTags := this.GetString("articleTags") articleTags = strings.Replace(articleTags, ";", ";", -1) article.ModifyArticleById(articleId, topicTitle, content, int64(categoryId), articleTags, int64(this.userId), isDraft) if isDraft { this.Redirect("/draftList", 302) } else { this.Redirect("/articleList", 302) } } }
// //根据分类列出文章 todo 错误处理 func (this *Home) Category() { this.TplNames = "home.html" var id int var err error if id, err = strconv.Atoi(this.Input().Get("id")); err == nil { } currentPage := 1 //获取上一页的页码 if page, err := strconv.Atoi(this.Input().Get("p")); err == nil { currentPage = page } var count int64 this.Data["topicList"], count = article.GetArticlesByCategoryId(int64(id), pageLimit, int64(currentPage)) //todo this.Data["categoryList"] = article.GetCategories(false) pagination.SetPaginator(this.Ctx, pageLimit, count) }
//创建新文章 func (this *Article) NewArticle() { this.TplNames = "new_article.html" this.Data["categories"] = article.GetCategories(true) }