예제 #1
0
파일: article.go 프로젝트: ruoL/code
// 显示文章首页
func (this *ArticleController) Get() {
	//获取类型
	atype := this.Ctx.Input.Param(":type")
	var state []int
	if "trash" != atype {
		state = []int{1}
	} else {
		state = []int{0}
	}

	// 处理分页
	pageSize, err := beego.AppConfig.Int("pagesize")
	if err != nil {
		pageSize = 10
	}
	count, err := models.GetArticleCount(state)
	if err != nil {
		beego.Error(err)
	}
	paginator := pagination.NewPaginator(this.Ctx.Request, pageSize, count)
	this.Data["paginator"] = paginator

	// 查询数据库
	this.Data["Articles"], err = models.GetArticles(paginator.Offset(), pageSize, state)
	if err != nil {
		beego.Error(err)
	}
	this.Data["IsTrash"] = atype == "trash"
	this.Data["Title"] = "管理后台 - 所有文章"
	this.Layout = "manager/layout.html"
	this.TplNames = "manager/article_index.html"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["HtmlHead"] = "manager/article_index_heade.html"
	return
}
예제 #2
0
파일: index.go 프로젝트: ruoL/code
//博客首页
func (this *IndexController) Get() {
	//先处理分页
	pageSize, err := beego.AppConfig.Int("pagesize")
	if err != nil {
		beego.Error(err)
	}
	count, err := models.GetArticleCount([]int{1})
	if err != nil {
		beego.Error(err)
	}
	paginator := pagination.NewPaginator(this.Ctx.Request, pageSize, count)
	this.Data["paginator"] = paginator

	this.Data["Articles"], err = models.GetArticles(paginator.Offset(), pageSize, []int{1})
	if err != nil {
		beego.Error(err)
	}
	this.Data["Categories"], err = models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
	this.Layout = "index/layout.html"
	this.TplNames = "index/index.html"
	return
}