Esempio n. 1
0
func (h *bookHandler) DeleteHandler(ctx *her.Context, id string) {
	result := bookModel.Delete(id)
	if result {
		ctx.Redirect("/")
		return
	}
	ctx.Redirect("/")
	return
}
Esempio n. 2
0
func (h *bookHandler) CreateHandler(ctx *her.Context) {
	form := form.NewBookForm(ctx)
	tmpl := map[string]interface{}{}

	if ctx.Request.Method == "POST" {
		if form.Form.Validate() {
			bookModel := &model.Book{}
			bookModel.UserName = form.UserName.Value()
			bookModel.Content = form.Content.Value()
			result := bookModel.Insert()
			if result {
				tmpl["success"] = "发布成功"
			}
		}
	}
	tmpl["form"] = form
	ctx.Render("create.html", tmpl)
}
Esempio n. 3
0
func (h *bookHandler) HomeHandler(ctx *her.Context) {
	books := bookModel.GetAll()
	tmpl := map[string]interface{}{}
	tmpl["books"] = books
	ctx.Render("index.html", tmpl)
}