Exemplo n.º 1
0
// 查看文章详情
func (c *TopicController) View() {
	c.TplNames = "topic_view.html"

	// 获取文章数据
	topic, err := models.GetTopic(c.Ctx.Input.Param("0"))
	if err != nil {
		beego.Error(err)
		c.Redirect("/", 302)
		return
	}
	// 先将文章内容数据丢出给前台,就不论是否获取评论成功与否,文章都能显示
	c.Data["Topic"] = topic
	c.Data["Label"] = strings.Split(topic.Label, " ")
	c.Data["Tid"] = c.Ctx.Input.Param("0")

	// 获取评论数据
	replies, err := models.GetAllReplies(c.Ctx.Input.Param("0"))
	if err != nil {
		beego.Error(err)
		return
	}

	c.Data["Replies"] = replies
	c.Data["IsLogin"] = checkLogin(c.Ctx)
}
Exemplo n.º 2
0
// 修改文章
func (c *TopicController) Modify() {
	c.TplNames = "topic_modify.html"

	if !checkLogin(c.Ctx) {
		c.Redirect("/login", 302)
		return
	}

	tid := c.Input().Get("tid")
	topic, err := models.GetTopic(tid)
	if err != nil {
		beego.Error(err)
		c.Redirect("/", 302)
		return
	}
	c.Data["Topic"] = topic
	c.Data["Tid"] = tid
}