Exemple #1
0
func (this *MainController) Get() {
	page, err := this.GetInt64("p", 1)
	if err != nil {
		beego.Error(err)
	}

	extend := map[string]string{}
	tid := this.GetString("tid", "")
	key := this.GetString("key")
	if tid != "" {
		extend["type_id"] = tid
	}

	beego.Info(extend)
	maps, err := models.GetArtPageList(10, (page-1)*10, extend, key)

	if err != nil {
		beego.Error(err)
	}
	count, err := models.GetCount(extend, key)
	if err != nil {
		beego.Error(err)
	}
	p := pagination.NewPaginator(this.Ctx.Request, 10, count)
	beego.Info(p)
	this.Data["paginator"] = p
	types := models.GetAllType()
	this.Data["articles"] = maps
	this.Data["types"] = types
	this.Data["key"] = key
	beego.AppConfig.String("banner1.name")

	this.TplNames = "index.tpl"
}
Exemple #2
0
func (this *AticleController) Add() {

	var article models.Article
	valid := validation.Validation{}
	title := this.GetString("title", "")
	content := this.GetString("content", "")
	typeId, _ := this.GetInt("typeId")
	article.Content = content
	article.Title = title
	article.TypeId = typeId
	this.Data["art"] = article
	this.GetLayout("admin/edit.tpl")
	b, err := valid.Valid(&article)
	if err != nil {
		beego.Error(err)
	}
	if !b {
		this.Data["err"] = valid.Errors
		return
	}

	models.InsertArt(&article)
	types := models.GetAllType()
	this.Data["types"] = types
	article.Content = ""
	article.Title = ""
	article.TypeId = -1
	this.Data["art"] = article

}
Exemple #3
0
func (this *AticleController) Edit() {

	types := models.GetAllType()
	this.Data["types"] = types
	this.Data["art"] = &models.Article{}
	this.Data["op"] = "add"
	//this.TplN""ames= "admin/edit.tpl";
	this.GetLayout("admin/edit.tpl")
}
Exemple #4
0
func (this *AticleController) ShowModify() {
	id, err := this.GetInt("id")
	if err != nil {
		this.ToJsonFails("请输入正确的id")
		return
	}
	types := models.GetAllType()
	art := &models.Article{Id: id}
	models.GetByProperty(art)
	this.Data["types"] = types
	this.Data["art"] = art
	this.Data["op"] = "modify"
	this.GetLayout("admin/edit.tpl")
}
Exemple #5
0
func (this *ArticleController) View() {
	idstr := this.Ctx.Input.Param("0")

	id, err := strconv.Atoi(strings.Split(idstr, ".")[0])
	if err != nil {
		beego.Error(err)
	}
	art := getArticle(id)
	//计数
	addClickNum(id)

	this.Data["article"] = art
	types := models.GetAllType()
	this.Data["types"] = types
	this.Data["headStr"] = art.Title
	this.TplNames = "view.tpl"
}
Exemple #6
0
func (this *AticleController) Modify() {
	art := models.Article{}
	if err := this.ParseForm(&art); err != nil {
		beego.Error(err)

		return
	}
	beego.Info(art)
	if _, err := utils.NewOrm().Update(&art, "Title", "Content", "TypeId", "ModifyTime"); err != nil {
		types := models.GetAllType()
		models.GetByProperty(&art)
		this.Data["types"] = types
		this.Data["art"] = art
		this.Data["op"] = "modify"
		this.GetLayout("admin/edit.tpl")
		return
	}
	this.Manage()
}