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) }
func (t *TopicController) Post() { if !checkAccount(t.Ctx) { t.TplNames = "login.html" return } op := t.Input().Get("op") switch op { case "add": title := t.Input().Get("title") content := t.Input().Get("content") category := t.Input().Get("category") _, fh, ferr := t.GetFile("attachment") if ferr != nil { beego.Error(ferr) } var attachment string if fh != nil { attachment = fh.Filename beego.Info(attachment) ferr = t.SaveToFile("attachment", path.Join("attachment", attachment)) if ferr != nil { beego.Error(ferr) } } err := models.AddTopic(title, content, category, attachment) if err != nil { beego.Error(err) } t.Redirect("/topic", 301) return case "edit": return case "editsubmit": id := t.Input().Get("id") title := t.Input().Get("title") content := t.Input().Get("content") category := t.Input().Get("category") _, fh, ferr := t.GetFile("attachment") if ferr != nil { beego.Error(ferr) } var attachment string if fh != nil { attachment = fh.Filename fmt.Println("#############################################", attachment) beego.Info(attachment) ferr = t.SaveToFile("attachment", path.Join("attachment", attachment)) if ferr != nil { beego.Error(ferr) } } err := models.UpdateTopic(id, title, content, category, attachment) if err != nil { beego.Error(err) } t.Redirect("/topic", 301) return default: t.Data["IsTopic"] = true t.TplNames = "topic.html" var err error t.Data["Topics"], err = models.GetAllTopic() if err != nil { beego.Error(nil) } } }