24
24
博客主要的路由规则如下所示:
25
25
26
26
//显示博客首页
27
- beego.RegisterController ("/", &controllers.IndexController{})
27
+ beego.Router ("/", &controllers.IndexController{})
28
28
//查看博客详细信息
29
- beego.RegisterController ("/view/:id([0-9]+)", &controllers.ViewController{})
29
+ beego.Router ("/view/:id([0-9]+)", &controllers.ViewController{})
30
30
//新建博客博文
31
- beego.RegisterController ("/new", &controllers.NewController{})
31
+ beego.Router ("/new", &controllers.NewController{})
32
32
//删除博文
33
- beego.RegisterController ("/delete/:id([0-9]+)", &controllers.DeleteController{})
33
+ beego.Router ("/delete/:id([0-9]+)", &controllers.DeleteController{})
34
34
//编辑博文
35
- beego.RegisterController ("/edit/:id([0-9]+)", &controllers.EditController{})
35
+ beego.Router ("/edit/:id([0-9]+)", &controllers.EditController{})
36
36
37
37
38
38
## 数据库结构
@@ -66,8 +66,7 @@ ViewController:
66
66
}
67
67
68
68
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"])
71
70
this.Data["Post"] = models.GetBlog(id)
72
71
this.Layout = "layout.tpl"
73
72
this.TplNames = "view.tpl"
@@ -101,8 +100,7 @@ EditController
101
100
}
102
101
103
102
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"])
106
104
this.Data["Post"] = models.GetBlog(id)
107
105
this.Layout = "layout.tpl"
108
106
this.TplNames = "new.tpl"
@@ -126,8 +124,10 @@ DeleteController
126
124
}
127
125
128
126
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.Params[":id"])
128
+ blog := GetBlog(id int)
129
+ this.Data["Post"] = blog
130
+ models.DelBlog(blog)
131
131
this.Ctx.Redirect(302, "/")
132
132
}
133
133
0 commit comments