func (this *MainController) Get() { this.Data["IsHome"] = true this.TplNames = "index.html" this.Data["IsLogin"] = checkAccount(this.Ctx) topics, err := models.GetAllTopics(this.Input().Get("cate"), this.Input().Get("tag"), true) for _, topic := range topics { if len(topic.Content) > 200 { topic.Content = string([]byte(topic.Content)[:200]) } } if err != nil { beego.Error(err) } else { this.Data["Topics"] = topics } Categories, err := models.GetAllCategories() if err != nil { beego.Error(err) } this.Data["Categories"] = Categories this.locale() //locale }
func (this *CategoryController) Get() { op := this.Input().Get("op") switch op { case "add": if !checkAccount(this.Ctx) { this.Redirect("/login", 302) return } name := this.Input().Get("name") if len(name) == 0 { break } err := models.AddCategory(name) if err != nil { beego.Error(err) } this.Redirect("/category", 302) return case "del": if !checkAccount(this.Ctx) { this.Redirect("/login", 302) return } id := this.Input().Get("id") if len(id) == 0 { break } err := models.DeleteTopics(id) if err != nil { beego.Error(err) } err = models.DeleteCategory(id) if err != nil { beego.Error(err) } this.Redirect("/category", 302) return } this.TplNames = "category.html" this.Data["IsCategory"] = true this.Data["IsLogin"] = checkAccount(this.Ctx) var err error this.Data["Categories"], err = models.GetAllCategories() if err != nil { beego.Error(err) } this.locale() }