Esempio n. 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"
}
Esempio n. 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"
}
Esempio n. 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"
}
Esempio n. 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()
}
Esempio n. 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()
}
Esempio n. 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()
}
Esempio n. 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()
}