Exemple #1
0
func (this *NewController) Post() {
	inputs := this.Input()
	var blog models.Blog
	blog.Title = inputs.Get("title")
	blog.Content = inputs.Get("content")
	blog.Created = time.Now()
	models.SaveBlog(blog)
	this.Ctx.Redirect(302, "/")
}
func (this *EditController) Post() {
	inputs := this.Input()
	var id int
	this.Ctx.Input.Bind(&id, ":id")
	var blog models.Blog
	blog.Index = id
	blog.Title = inputs.Get("title")
	blog.Content = inputs.Get("content")
	models.SaveBlog(blog)
	this.Ctx.Redirect(302, "/")
}
Exemple #3
0
func (this *BlogController) Post() {
	result := make(map[string]interface{})
	result["succ"] = "succ"

	online_user := this.GetSession("online_user")
	uid, err := helper.FormatSessUid(online_user)
	if err != nil {
		result["succ"] = "err"
		result["msg"] = this.Tr("op_no_user")
		this.Data["json"] = result
		this.ServeJson()
	}

	category, _ := this.GetInt("category")
	content := this.GetString("content")
	// contentText := this.GetString("contentText")
	tag := this.GetString("tag")
	title := this.GetString("title")
	canComment, err := this.GetInt("canComment")
	if err != nil {
		beego.Error(err)
		canComment = 1
	}

	b := new(models.Blog)
	b.Title = title
	b.Content = content
	b.Uid = uid
	b.Created = time.Now()
	b.State = 1
	b.CanComment = int(canComment)
	b.Tag = tag
	b.CategoryId = category
	_, err = models.SaveBlog(b)
	if err != nil {
		beego.Error(err)
		result["succ"] = "err"
		result["msg"] = this.Tr("blog.save_err")
	} else {
		result["msg"] = this.Tr("blog.save_succ")
	}

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