2424博客主要的路由规则如下所示:
2525
2626 //显示博客首页
27- beego.RegisterController ("/", &controllers.IndexController{})
27+ beego.Router ("/", &controllers.IndexController{})
2828 //查看博客详细信息
29- beego.RegisterController ("/view/:id([0-9]+)", &controllers.ViewController{})
29+ beego.Router ("/view/:id([0-9]+)", &controllers.ViewController{})
3030 //新建博客博文
31- beego.RegisterController ("/new", &controllers.NewController{})
31+ beego.Router ("/new", &controllers.NewController{})
3232 //删除博文
33- beego.RegisterController ("/delete/:id([0-9]+)", &controllers.DeleteController{})
33+ beego.Router ("/delete/:id([0-9]+)", &controllers.DeleteController{})
3434 //编辑博文
35- beego.RegisterController ("/edit/:id([0-9]+)", &controllers.EditController{})
35+ beego.Router ("/edit/:id([0-9]+)", &controllers.EditController{})
3636
3737
3838## 数据库结构
@@ -66,8 +66,7 @@ ViewController:
6666 }
6767
6868 func (this *ViewController) Get() {
69- inputs := this.Input()
70- id, _ := strconv.Atoi(this.Ctx.Params[":id"])
69+ id, _ := strconv.Atoi(this.Ctx.Input.Params(":id"))
7170 this.Data["Post"] = models.GetBlog(id)
7271 this.Layout = "layout.tpl"
7372 this.TplNames = "view.tpl"
@@ -101,8 +100,7 @@ EditController
101100 }
102101
103102 func (this *EditController) Get() {
104- inputs := this.Input()
105- id, _ := strconv.Atoi(this.Ctx.Params[":id"])
103+ id, _ := strconv.Atoi(this.Ctx.Input.Params(":id"))
106104 this.Data["Post"] = models.GetBlog(id)
107105 this.Layout = "layout.tpl"
108106 this.TplNames = "new.tpl"
@@ -126,8 +124,10 @@ DeleteController
126124 }
127125
128126 func (this *DeleteController) Get() {
129- id, _ := strconv.Atoi(this.Ctx.Params[":id"])
130- this.Data["Post"] = models.DelBlog(id)
127+ id, _ := strconv.Atoi(this.Ctx.Input.Params(":id"))
128+ blog := GetBlog(id int)
129+ this.Data["Post"] = blog
130+ models.DelBlog(blog)
131131 this.Ctx.Redirect(302, "/")
132132 }
133133
0 commit comments