//创建相册 func (this *AlbumController) Add() { if this.Ctx.Request.Method == "POST" { rank, _ := this.GetInt("rank") var album models.Album album.Name = strings.TrimSpace(this.GetString("albumname")) album.Cover = strings.TrimSpace(this.GetString("cover")) album.Rank = int8(rank) album.Posttime = time.Now() if err := album.Insert(); err != nil { this.showmsg(err.Error()) } this.Redirect("/admin/album/list", 302) } this.display() }
//修改 func (this *AlbumController) Edit() { id, _ := this.GetInt64("albumid") album := models.Album{Id: id} if album.Read() != nil { this.Abort("404") } if this.Ctx.Request.Method == "POST" { rank, _ := this.GetInt("rank") album.Cover = this.GetString("cover") album.Name = this.GetString("albumname") album.Rank = int8(rank) album.Update() this.Redirect("/admin/album/list", 302) } this.Data["album"] = album this.display() }