func (this *TopicController) Post() { if !checkAccount(this.Ctx) { this.Redirect("/login", 302) return } // 解析表单 tid := this.Input().Get("tid") title := this.Input().Get("title") content := this.Input().Get("content") category := this.Input().Get("category") var err error if len(tid) == 0 { err = models.AddTopic(title, category, content) } else { err = models.ModifyTopic(tid, title, category, content) } if err != nil { beego.Error(err) } this.Redirect("/topic", 302) }
//增加修改文章,保存到数据库中 func (this *TopicController) Post() { if !checkAccount(this.Ctx) { this.Redirect("/login", 302) return } tid := this.Input().Get("tid") title := this.Input().Get("title") content := this.Input().Get("content") category := this.Input().Get("category") label := this.Input().Get("label") //上传附件 _, fh, err := this.GetFile("attachment") if err != nil { beego.Error(err) } var attachment string if fh != nil { //保存附件 attachment = fh.Filename beego.Info(attachment) err = this.SaveToFile("attachment", path.Join("attachment", attachment)) if err != nil { beego.Error(err) } } if len(tid) == 0 { err = models.AddTopic(title, content, category, label, attachment) } else { err = models.ModifyTopic(tid, title, content, category, label, attachment) } if err != nil { beego.Error(err) } this.Redirect("topic", 301) return }
func (this *TopicController) Post() { if !checkAccount(this.Ctx) { this.Redirect("/login", 302) } /* 解析表单 */ title := this.Input().Get("title") category := this.Input().Get("category") content := this.Input().Get("content") tid := this.Input().Get("tid") var err error if len(tid) == 0 { err = models.AddTopic(title, content, category) if models.CheckCategory(category) { beego.Debug("had") models.UpdateCategory(category) } else { beego.Debug("Not ! ") models.AddCategory(category) } } else { err = models.ModifyTopic(tid, title, content, category) if models.CheckCategory(category) { beego.Debug("had") } else { beego.Debug("Not ! ") models.AddCategory(category) } } if err != nil { beego.Error(err) } this.Redirect("/topic", 302) }