// 修改文章页面 func (this *TopicController) ModifyTopic() { beego.ReadFromRequest(&this.Controller) flash := beego.NewFlash() if checkAccountSession(&this.Controller) { //验证用户是否已登录 id, err := strconv.ParseInt(this.Ctx.Input.Param(":id"), 10, 64) if err != nil { beego.Error("获取文章id失败") flash.Error("获取文章id失败!") flash.Store(&this.Controller) return } topic := models.ViewTopicById(id) this.Data["Topic"] = topic this.TplNames = "modify_topic.html" } else { flash.Error("您尚未登录,请登录!") flash.Store(&this.Controller) this.Redirect("/login", 302) //跳转到登录页 return } }
// 根据文章id查看文章 func (this *TopicController) ViewTopic() { beego.ReadFromRequest(&this.Controller) flash := beego.NewFlash() if this.GetSession("user") != nil { user := this.GetSession("user").(*models.User) //从Session中获取用户信息 this.Data["Nickname"] = user.Nickname this.Data["Username"] = user.Username this.Data["IsLogin"] = true this.Data["IsTopic"] = true } id, err := strconv.ParseInt(this.Ctx.Input.Param(":id"), 10, 64) if err != nil { beego.Error("获取文章id失败" + err.Error()) flash.Error("获取文章id失败!") flash.Store(&this.Controller) return } topic := models.ViewTopicById(id) this.Data["Topic"] = topic this.TplNames = "view_topic.html" }