示例#1
0
文件: post.go 项目: Raysmond/RaysGo
// My posts
func (this *PostController) List() {
	this.TplNames = "post/myposts.html"
	this.Data["Title"] = "My posts"

	posts := make([]*models.Node, 0)
	err := models.Engine.Where("Uid = ?", this.User().Id).Desc("id").Find(&posts)
	if err == nil {
		this.Data["Posts"] = posts
		if tags, err := models.GetUserTags(this.User().Id); err == nil {
			this.Data["Tags"] = *tags
		}
	} else {
		this.Abort("404")
	}
}
示例#2
0
文件: post.go 项目: Raysmond/RaysGo
// TODO
func (this *PostController) Tag() {
	name := this.GetParam(":name")
	tag := models.CategoryTerm{Name: name, IUser: models.User{Id: this.User().Id}}
	if has, err := models.Engine.Get(&tag); !has || err != nil {
		this.Abort("404")
	}
	posts := make([]models.Node, 0)
	models.Engine.Join("inner", "node_category_term", "node_category_term.nid = node.id").Where("node_category_term.tid = ?", tag.Id).Find(&posts)
	if tags, err := models.GetUserTags(this.User().Id); err == nil {
		this.Data["Tags"] = *tags
	}

	this.Data["Posts"] = posts
	this.Data["Tag"] = tag
	this.Data["Title"] = tag.Name
	this.TplNames = "post/tag.html"
}