示例#1
0
func (this *HomeController) ArticleList() {
	cid := this.Ctx.Input.Param(":cid")
	filter := map[string]interface{}{"categoryId": cid, "keywords": ""} //初始化一个无用定义,防止filter为nil

	article := new(models.Article)
	list := article.GetList(15, 1, filter)

	this.Data["articles"] = list
	this.TplNames = "front/articlelist.tpl"
}
示例#2
0
func (this *HomeController) ArticleDetail() {
	id, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
	article := new(models.Article)
	err := article.GetArticleInfo(id)
	if err != nil {
		fmt.Println(err)
	}
	this.Data["article"] = article

	this.TplNames = "front/articledetail.tpl"
}
示例#3
0
func (this *HomeController) Get() {
	filter := map[string]interface{}{"categoryId": "", "keywords": ""} //初始化一个无用定义,防止filter为nil

	article := new(models.Article)
	list := article.GetList(15, 1, filter)

	this.Data["Website"] = "gocms"
	this.Data["Email"] = "*****@*****.**"
	this.Data["articles"] = list
	this.TplNames = "front/index.tpl"
}
示例#4
0
func (this *ArticleController) GetData() {
	id, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
	article := new(models.Article)
	err := article.GetArticleInfo(id)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(article)
	this.Data["json"] = article
	this.ServeJson()
}
示例#5
0
func (this *ArticleController) Delete() {
	var ajaxResult models.AjaxResult
	id := this.Ctx.Input.Param(":id")
	articleId, err := strconv.Atoi(id)
	if err != nil {
		ajaxResult = models.AjaxResult{Success: false}
		ajaxResult.Error = err.Error()
	} else {
		article := new(models.Article)
		ajaxResult = article.Delete(articleId)
	}

	this.Data["json"] = ajaxResult
	this.ServeJson()
}
示例#6
0
func (this *ArticleController) GetDataList() {
	var filter map[string]interface{}
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &filter)
	if err != nil {
		fmt.Println(err)
	}
	pageSize, err := strconv.Atoi(filter["pageSize"].(string))
	pageNo, err := strconv.Atoi(filter["pageNo"].(string))
	result := map[string]interface{}{"totalCount": 0, "data": nil}
	article := new(models.Article)
	totalCount := article.GetCount(filter)
	list := article.GetList(pageSize, pageNo, filter)
	result["totalCount"] = totalCount
	result["data"] = list
	this.Data["json"] = result
	fmt.Println(result)
	this.ServeJson()
}
示例#7
0
func (this *ArticleController) Save() {
	ajaxResult := new(models.AjaxResult)
	article := new(models.Article)
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &article)
	if err != nil {
		ajaxResult.Error = err.Error()
	} else {
		err = article.Save()
		if err != nil {
			ajaxResult.Error = err.Error()
		} else {
			ajaxResult.Success = true
			ajaxResult.Msg = &article
		}
	}

	this.Data["json"] = ajaxResult
	this.ServeJson()
}