func (c *Topic) EditPost(id int64, topic models.Topic) revel.Result { topic.Validate(c.Validation) if c.Validation.HasErrors() { c.Validation.Keep() c.FlashParams() return c.Redirect(routes.Topic.Edit(id)) } topic_ := models.FindTopicById(id) if topic_.Id == 0 { return c.NotFound("帖子不存在") } topic_.Title = topic.Title topic_.CategoryId = topic.CategoryId topic_.Content = topic.Content if topic_.Save() { c.Flash.Success("编辑帖子成功") } else { c.Flash.Error("编辑帖子失败") } return c.Redirect(routes.Topic.Edit(id)) }
func (c *Topic) Edit(id int64) revel.Result { title := "编辑帖子" topic := models.FindTopicById(id) if topic.Id == 0 { return c.NotFound("帖子不存在") } categories := models.GetCategories() c.Render(title, topic, categories) return c.RenderTemplate("Topic/New.html") }
// 帖子详细 func (c *Topic) Show(id int64) revel.Result { topic := models.FindTopicById(id) if topic.Id == 0 { return c.NotFound("帖子不存在") } topic.Hits += 1 topic.Save() replies := models.GetReplies(id) categories := models.GetCategories() title := topic.Title return c.Render(title, topic, replies, categories) }