Exemple #1
0
func (this *MainController) Get() {
	this.Data["IsHome"] = true
	this.Data["IsLogin"] = checkAccount(this.Ctx)
	this.TplName = "home.html"
	topics, err := models.GetAllTopics(this.Input().Get("cate"), true)
	if err != nil {
		beego.Error(err.Error())
	} else {
		this.Data["Topics"] = topics
	}
	category, err := models.GetAllCategories()
	if err != nil {
		beego.Error(err.Error())
	} else {
		this.Data["Categorys"] = category
	}
	return
}
Exemple #2
0
func (this *CategoryController) Get() {
	this.Data["IsLogin"] = checkAccount(this.Ctx)
	op := this.Input().Get("op")

	switch op {
	case "add":
		{
			name := this.Input().Get("name")
			if len(name) == 0 {
				break
			}
			err := models.AddCategory(name)
			if err != nil {
				beego.Error(err)
			}

			this.Redirect("/category", 301)
			return
		}
	case "del":
		{
			id := this.Input().Get("id")
			if len(id) == 0 {
				break
			}
			err := models.DelCategory(id)
			if err != nil {
				beego.Error(err)
			}

			this.Redirect("/category", 301)
			return
		}
	}
	this.Data["IsCategory"] = true
	this.TplName = "category.html"
	var err error
	this.Data["Categories"], err = models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
}