码农笔录博客源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.0 KiB

package controllers
import (
"beeblog/models"
"beeblog/service"
6 years ago
"github.com/astaxie/beego"
"strconv"
)
type BlogController struct {
beego.Controller
}
func (this *BlogController) Save() {
6 years ago
title := this.GetString("title")
blogHtml := this.GetString("blogHtml")
catory := this.GetString("catory")
catoryId, _ := strconv.ParseInt(catory, 10, 64)
labels := this.GetStrings("labels[]")
6 years ago
blog := &models.Blog{Title: title, BlogHtml: blogHtml, CategoryId: catoryId, UserId: 1}
err := service.SaveBlog(blog, labels)
6 years ago
if err == nil {
this.Data["json"] = blog
} else {
this.Data["json"] = models.ReurnError(500,"保存失败")
}
this.ServeJSON()
}
func (this *BlogController) Get() {
idStr := this.Ctx.Input.Param(":id")
id, _ := strconv.ParseInt(idStr, 10, 64)
blog, err := service.GetBlog(id)
6 years ago
if err == nil {
this.Data["Blog"] = blog
}
this.TplName = "blog.html"
}
6 years ago
func (this *BlogController) New() {
this.TplName = "newblog.html"
6 years ago
}
6 years ago
func (this *BlogController) Blog1() {
this.TplName = "blog1.html"
}