本文整理匯總了Golang中github.com/lisijie/goblog/models.Post.Read方法的典型用法代碼示例。如果您正苦於以下問題:Golang Post.Read方法的具體用法?Golang Post.Read怎麽用?Golang Post.Read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/lisijie/goblog/models.Post
的用法示例。
在下文中一共展示了Post.Read方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Batch
//批處理
func (this *ArticleController) 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))
}
}
var post models.Post
switch op {
case "topub": //移到已發布
post.Query().Filter("id__in", idarr).Update(orm.Params{"status": 0})
case "todrafts": //移到草稿箱
post.Query().Filter("id__in", idarr).Update(orm.Params{"status": 1})
case "totrash": //移到回收站
post.Query().Filter("id__in", idarr).Update(orm.Params{"status": 2})
case "delete": //批量刪除
for _, id := range idarr {
obj := models.Post{Id: id}
if obj.Read() == nil {
obj.Delete()
}
}
}
this.Redirect(this.Ctx.Request.Referer(), 302)
}
示例2: Show
//文章顯示
func (this *MainController) Show() {
var (
post models.Post
err error
)
urlname := this.Ctx.Input.Param(":urlname")
if urlname != "" {
post.Urlname = urlname
err = post.Read("urlname")
} else {
id, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
post.Id = int64(id)
err = post.Read()
}
if err != nil || post.Status != 0 {
this.Abort("404")
}
post.Views++
post.Update("Views")
this.Data["post"] = post
this.setHeadMetas(post.Title, strings.Trim(post.Tags, ","), post.Title)
this.display("article")
}
示例3: Delete
//刪除
func (this *ArticleController) Delete() {
id, _ := this.GetInt("id")
post := models.Post{Id: id}
if post.Read() == nil {
post.Delete()
}
this.Redirect("/admin/article/list", 302)
}
示例4: Edit
//編輯
func (this *ArticleController) Edit() {
id, _ := this.GetInt("id")
post := models.Post{Id: id}
if post.Read() != nil {
this.Abort("404")
}
post.Tags = strings.Trim(post.Tags, ",")
this.Data["post"] = post
this.display()
}
示例5: Save
//保存
func (this *ArticleController) Save() {
var (
id int64 = 0
title string = strings.TrimSpace(this.GetString("title"))
content string = this.GetString("content")
tags string = strings.TrimSpace(this.GetString("tags"))
urlname string = strings.TrimSpace(this.GetString("urlname"))
color string = strings.TrimSpace(this.GetString("color"))
status int64 = 0
istop int8 = 0
urltype int8 = 1
post models.Post
)
if title == "" {
this.showmsg("標題不能為空!")
}
id, _ = this.GetInt("id")
status, _ = this.GetInt("status")
if this.GetString("istop") == "1" {
istop = 1
}
if this.GetString("urltype") == "2" {
urltype = 2
}
if status != 1 && status != 2 {
status = 0
}
addtags := make([]string, 0)
//標簽過濾
if tags != "" {
tagarr := strings.Split(tags, ",")
for _, v := range tagarr {
if tag := strings.TrimSpace(v); tag != "" {
exists := false
for _, vv := range addtags {
if vv == tag {
exists = true
break
}
}
if !exists {
addtags = append(addtags, tag)
}
}
}
}
if id < 1 {
post.Userid = this.userid
post.Author = this.username
post.Posttime = this.getTime()
post.Insert()
} else {
post.Id = id
if post.Read() != nil {
goto RD
}
if post.Tags != "" {
var tagobj models.Tag
var tagpostobj models.TagPost
oldtags := strings.Split(strings.Trim(post.Tags, ","), ",")
//標簽統計-1
tagobj.Query().Filter("name__in", oldtags).Update(orm.Params{"count": orm.ColValue(orm.Col_Minus, 1)})
//刪掉tag_post表的記錄
tagpostobj.Query().Filter("postid", post.Id).Delete()
}
}
if len(addtags) > 0 {
for _, v := range addtags {
tag := models.Tag{Name: v}
if tag.Read("Name") == orm.ErrNoRows {
tag.Count = 1
tag.Insert()
} else {
tag.Count += 1
tag.Update("Count")
}
tp := models.TagPost{Tagid: tag.Id, Postid: post.Id, Poststatus: int8(status), Posttime: this.getTime()}
tp.Insert()
}
post.Tags = "," + strings.Join(addtags, ",") + ","
}
post.Status = int8(status)
post.Title = title
post.Color = color
post.Istop = istop
post.Content = content
post.Urlname = urlname
post.Urltype = urltype
post.Updated = this.getTime()
post.Update()
RD:
//.........這裏部分代碼省略.........