Example #1
0
//todo 上一篇,下一篇
func (this *Home) Article() {
	this.TplNames = "article.html"
	topicId := this.Input().Get("id")
	if topicId == "" {
		this.Redirect("/", 302)
		return
	}

	article, err := article.GetArticleById(topicId)
	if err != nil {
		//找不到该文章
		this.Abort("404")
	}

	this.Data["article"] = article
}
Example #2
0
//修改文章 文章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)
		}
	}
}