Exemple #1
0
func (manage *ManageController) Update() {
	o := orm.NewOrm()
	o.Using("default")
	flash := beego.NewFlash()

	// convert the string value to an int
	if articleId, err := strconv.Atoi(manage.Ctx.Input.Param(":id")); err == nil {
		article := models.Article{Id: articleId}
		// attempt to load the record from the database
		if o.Read(&article) == nil {
			// set the Client and Url properties to arbitrary values
			article.Client = "Sitepoint"
			article.Url = "http://www.google.com"
			if num, err := o.Update(&article); err == nil {
				flash.Notice("Record Was Updated.")
				flash.Store(&manage.Controller)
				beego.Info("Record Was Updated. ", num)
			}
		} else {
			flash.Notice("Record Was NOT Updated.")
			flash.Store(&manage.Controller)
			beego.Error("Couldn't find article matching id: ", articleId)
		}
	} else {
		flash.Notice("Record Was NOT Updated.")
		flash.Store(&manage.Controller)
		beego.Error("Couldn't convert id from a string to a number. ", err)
	}

	// redirect afterwards
	manage.Redirect("/manage/view", 302)
}