func (this *CategoryController) Get() { this.Data["headerTitle"] = "Categories" this.TplNames = "category.html" this.Data["isCategory"] = true this.Data["isLogin"] = checkLogin(this.Ctx) op := this.Input().Get("op") if op == "add" { name := this.Input().Get("name") err := models.AddCategory(name) if err != nil { beego.Error(err) } } else if op == "del" { id := this.Input().Get("id") err := models.DeleteCategory(id) if err != nil { beego.Error(err) } } var err error this.Data["Categories"], err = models.AllCategories(false) if err != nil { beego.Error(err) } }
func (this *TopicController) Add() { this.TplNames = "topicForm.html" this.Data["headerTitle"] = "Add Topic" this.Data["headerPrefix"] = "添加" var err error this.Data["Categories"], err = models.AllCategories(true) if err != nil { beego.Error(err) } }
func (this *TopicController) Edit() { if checkLogin(this.Ctx) { id := this.Ctx.Input.Param("0") topic, err := models.GetTopic(id) if err != nil { beego.Error(err) } categories, err := models.AllCategories(true) if err != nil { beego.Error(err) } this.TplNames = "topicForm.html" this.Data["headerTitle"] = "Edit Topic" this.Data["headerPrefix"] = "修改" this.Data["Topic"] = topic this.Data["isTopic"] = true this.Data["isLogin"] = checkLogin(this.Ctx) this.Data["Categories"] = categories } else { this.Redirect("/login", 302) } }