示例#1
0
/*
文章显示,每浏览一次浏览量增加1
*/
func (this *IndexController) New() {
	uid := this.GetSession("sessionuid")

	/*
		输出文章信息
	*/
	article1, _ := models.Articleread(uid, 0)
	this.Data["article1"] = article1

	/*
		文章推荐信息
	*/
	articletuijian, _ := models.Articletuijian()
	this.Data["articletuijian"] = articletuijian

	/*
		随机文章信息
	*/
	articlerand, _ := models.Articlerand()
	this.Data["articlerand"] = articlerand

	articleid1 := this.Input().Get("articleid")
	articleid, _ := strconv.Atoi(articleid1)
	// this.Data["test"] = articleid
	// this.TplNames = "article/testarticle.html"
	// return
	//浏览量加1
	err := models.Articleviewsadd(articleid)
	if err != nil {
		return
	}
	article, _ := models.Articlefindwithaid(articleid1)
	userid := this.GetSession("sessionuid")
	var userinfo *models.User
	userinfo, err = models.Userinfowithuid(userid)
	if err != nil {
		return
	}
	if userinfo.Job != "" {
		this.Data["job"] = userinfo.Job
	} else {
		this.Data["job"] = "暂未填写"
	}
	if userinfo.Brief != "" {
		this.Data["brief"] = userinfo.Brief
	} else {
		this.Data["brief"] = "暂未填写"
	}
	this.Data["userinfo"] = userinfo
	this.Data["article"] = article
	this.TplNames = "blog/news.html"
}
示例#2
0
func (this *AdminController) Editarticle() {
	articleid, _ := this.GetInt32("aid")
	//如果文章id存在,进入编辑页面,不存在返回后台默认页面
	if articleid > 0 {
		//判断是否存在
		articleinfo, err := models.Articlefindwithaid(articleid)
		if err != nil {
			//没有找到相应文章,返回
			this.Redirect(this.Ctx.Request.Referer(), 302)
			return
		}
		if articleinfo.UpdateTime > 0 {
			//有更新时间就显示
			this.Data["updatetime"] = true
		}
		this.Data["article"] = articleinfo
		this.TplNames = "article/edit.html"
	} else {
		this.Redirect("/admin", 301)
	}
	// this.TplNames = "article/edit.html"
}