本文整理匯總了Golang中github.com/lisijie/goblog/models.Tag.Name方法的典型用法代碼示例。如果您正苦於以下問題:Golang Tag.Name方法的具體用法?Golang Tag.Name怎麽用?Golang Tag.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/lisijie/goblog/models.Tag
的用法示例。
在下文中一共展示了Tag.Name方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Category
//分類查看
func (this *MainController) Category() {
var (
page int
pagesize int
name string
err error
count int64
result map[string][]*models.Post
)
name = this.Ctx.Input.Param(":name")
if page, err = strconv.Atoi(this.Ctx.Input.Param(":page")); err != nil || page < 1 {
page = 1
}
if pagesize, err = strconv.Atoi(this.getOption("pagesize")); err != nil || pagesize < 1 {
pagesize = 20
} else {
pagesize *= 2
}
o := orm.NewOrm()
tag := new(models.Tag)
tag.Name = name
if o.Read(tag, "Name") != nil {
this.Abort("404")
}
count, _ = o.QueryTable(&models.TagPost{}).Filter("tagid", tag.Id).Filter("poststatus", 0).Count()
result = make(map[string][]*models.Post)
if count > 0 {
var tp []*models.TagPost
var list []*models.Post
var pids []int64 = make([]int64, 0)
o.QueryTable(&models.TagPost{}).Filter("tagid", tag.Id).Filter("poststatus", 0).OrderBy("-posttime").Limit(pagesize, (page-1)*pagesize).All(&tp)
for _, v := range tp {
pids = append(pids, v.Postid)
}
o.QueryTable(&models.Post{}).Filter("id__in", pids).All(&list)
for _, v := range list {
year := v.Posttime.Format("2006")
if _, ok := result[year]; !ok {
result[year] = make([]*models.Post, 0)
}
result[year] = append(result[year], v)
}
}
this.Data["tag"] = tag
this.Data["page"] = page
this.Data["pagesize"] = pagesize
this.Data["count"] = count
this.Data["result"] = result
this.Data["pagebar"] = models.NewPager(int64(page), int64(count), int64(pagesize), "/category/"+url.QueryEscape(tag.Name)).ToString()
this.setHeadMetas(tag.Name, tag.Name, tag.Name)
this.display("category")
}
示例2: batch
//批量操作
func (this *TagController) batch() {
ids := this.GetStrings("ids[]")
op := this.GetString("op")
idarr := make([]int64, 0)
for _, v := range ids {
if id, _ := strconv.Atoi(v); id > 0 {
idarr = append(idarr, int64(id))
}
}
switch op {
case "upcount": //更新統計
for _, id := range idarr {
obj := models.Tag{Id: id}
if obj.Read() == nil {
obj.UpCount()
}
}
case "merge": //合並到
toname := strings.TrimSpace(this.GetString("toname"))
if toname != "" && len(idarr) > 0 {
tag := new(models.Tag)
tag.Name = toname
if tag.Read("name") != nil {
tag.Count = 0
tag.Insert()
}
for _, id := range idarr {
obj := models.Tag{Id: id}
if obj.Read() == nil {
obj.MergeTo(tag)
obj.Delete()
}
}
tag.UpCount()
}
case "delete": //批量刪除
for _, id := range idarr {
obj := models.Tag{Id: id}
if obj.Read() == nil {
obj.Delete()
}
}
}
this.Redirect("/admin/tag", 302)
}
示例3: Category
//分類查看
func (this *MainController) Category() {
var (
page int
pagesize int
name string
err error
count int64
result map[string][]*models.Post
)
name = this.Ctx.Input.Param(":name")
if page, err = strconv.Atoi(this.Ctx.Input.Param(":page")); err != nil || page < 1 {
page = 1
}
if pagesize, err = strconv.Atoi(this.getOption("pagesize")); err != nil || pagesize < 1 {
pagesize = 20
} else {
pagesize *= 2
}
tagpost := new(models.TagPost)
tag := new(models.Tag)
tag.Name = name
if tag.Read("Name") != nil {
this.Abort("404")
}
query := tagpost.Query().Filter("tag_id", tag.Id).Filter("post_status", 0)
count, _ = query.Count()
result = make(map[string][]*models.Post)
if count > 0 {
var tp []*models.TagPost
var list []*models.Post
var pids []int = make([]int, 0)
query.OrderBy("-post_time").Limit(pagesize, (page-1)*pagesize).All(&tp)
for _, v := range tp {
pids = append(pids, v.PostId)
}
new(models.Post).Query().Filter("id__in", pids).All(&list)
for _, v := range list {
year := v.PostTime.Format("2006")
if _, ok := result[year]; !ok {
result[year] = make([]*models.Post, 0)
}
result[year] = append(result[year], v)
}
}
this.Data["tag"] = tag
this.Data["page"] = page
this.Data["pagesize"] = pagesize
this.Data["count"] = count
this.Data["result"] = result
this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, tag.Link()).ToString()
this.setHeadMetas(tag.Name, tag.Name, tag.Name)
this.display("category")
}