示例#1
0
/*
心灵鸡汤页面
*/
func (this *AdminController) Shuo() {
	op := this.Input().Get("op")
	uid := this.GetSession("sessionuid")
	if op == "add" {
		this.TplNames = "message/editshuo.html"
		this.Data["op"] = "add"
	} else if op == "edit" {
		shuoid, _ := this.GetInt("shuoid")

		shuo, err := models.Shuofind(shuoid)
		if err != nil {
			return
		}
		this.Data["content"] = shuo.Content
		this.TplNames = "message/editshuo.html"
		this.Data["op"] = "edit"
	} else {

		// this.TplNames = "message/shuo.html"
		// //查询数据,输出
		// uid := this.GetSession("sessionuid")
		// userinfo, err := models.Userinfowithuid(uid)
		// if err != nil {
		// 	return
		// }
		// chicken, err := models.Selectshuo(userinfo.Id)
		// if err != nil {
		// 	return
		// }
		// this.Data["chicken"] = chicken
		var page int
		var pagesize int = 10
		var list []*models.Chicken_soup
		var chicken models.Chicken_soup

		if page, _ = this.GetInt("page"); page < 1 {
			page = 1
		}
		offset := (page - 1) * pagesize

		count, _ := chicken.Query(uid).Count()
		if count > 0 {
			chicken.Query(uid).OrderBy("-id").Limit(pagesize, offset).All(&list)
		}

		this.Data["count"] = count
		this.Data["list"] = list
		this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, "/admin/shuo", true).ToString()
		this.TplNames = "message/shuo.html"

	}
}
示例#2
0
func (this *IndexController) Shuo() {
	//获取uid,判断是否非法访问
	cookieaccount := this.Ctx.GetCookie("cookieaccount")
	uid := this.GetSession("sessionuid")
	if len(cookieaccount) > 0 {
		if uid == nil {
			//获取用户账号account
			account := DecodeCookie(cookieaccount)
			//获取用户uid
			userinfo, _ := models.Userinfo(account)
			uid = userinfo.Id
			this.SetSession("sessionuid", uid)
		}
		//读取数据
		// userinfo, _ := models.Userinfowithuid(uid)
		// chicken, err := models.Selectshuo(userinfo.Id)
		// if err != nil {
		// 	return
		// }
		/*
			定义分页方法
		*/
		var page int
		var pagesize int = 10
		var list []*models.Chicken_soup
		var chicken models.Chicken_soup

		if page, _ = this.GetInt("page"); page < 1 {
			page = 1
		}
		offset := (page - 1) * pagesize

		count, _ := chicken.Query(uid).Count()
		if count > 0 {
			chicken.Query(uid).OrderBy("-id").Limit(pagesize, offset).All(&list)
		}

		//判断count是否为0
		if count == 0 {
			this.Data["noshuo"] = true
		} else {
			this.Data["noshuo"] = false
		}
		this.Data["count"] = count
		this.Data["list"] = list
		this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, "/index/shuo", true).ToString()
		this.TplNames = "blog/shuo.html"

	} else if uid != nil {
		//读取数据
		// userinfo, _ := models.Userinfowithuid(uid)
		// chicken, err := models.Selectshuo(userinfo.Id)
		// if err != nil {
		// 	return
		// }
		// this.Data["chicken"] = chicken
		// this.TplNames = "blog/shuo.html"
		/*
			定义分页方法
		*/
		var page int
		var pagesize int = 10
		var list []*models.Chicken_soup
		var chicken models.Chicken_soup

		if page, _ = this.GetInt("page"); page < 1 {
			page = 1
		}
		offset := (page - 1) * pagesize

		count, _ := chicken.Query(uid).Count()
		if count > 0 {
			chicken.Query(uid).OrderBy("-id").Limit(pagesize, offset).All(&list)
		}
		//判断count是否为0
		if count == 0 {
			this.Data["noshuo"] = true
		} else {
			this.Data["noshuo"] = false
		}
		this.Data["count"] = count
		this.Data["list"] = list
		this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, "/index/shuo", true).ToString()
		this.TplNames = "blog/shuo.html"
	} else {
		this.Redirect("/", 301)
	}
}