コード例 #1
0
ファイル: topic.go プロジェクト: nashtsai/gorevel
func (c Topic) NewPost(topic models.Topic, category int64) revel.Result {
	topic.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Topic.New())
	}

	topic.User = models.User{Id: c.user().Id}
	topic.Category = models.Category{Id: category}

	aff, _ := c.Engine.Insert(&topic)
	if aff > 0 {
		c.Flash.Success("发表新帖成功")
		cache.Flush()
	} else {
		c.Flash.Error("发表新帖失败")
	}

	return c.Redirect(routes.Topic.Index(1))
}