Skip to content

Commit 0136e88

Browse files
committed
文章添加跳转到详细页面
1 parent 9a9d076 commit 0136e88

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/myblog/controllers/topic.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package controllers
22

33
import (
4+
"fmt"
45
"github.com/astaxie/beego"
56
"myblog/models"
67
"strconv"
@@ -20,12 +21,12 @@ func (this *TopicController) Post() {
2021
content := this.Input().Get("content")
2122
classID, _ := strconv.Atoi(this.Input().Get("classID"))
2223

23-
err := models.AddTopic(title, content, int64(classID))
24+
id, err := models.AddTopic(title, content, int64(classID))
2425
if err != nil {
2526
beego.Error(err)
2627
}
27-
28-
this.Redirect("/", 302)
28+
str := fmt.Sprintf("%d", id)
29+
this.Redirect("/topic/view/"+str, 302)
2930
}
3031

3132
func (this *TopicController) Add() {

src/myblog/models/models.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func RegisterDB() {
5757
}
5858

5959
// 添加文章
60-
func AddTopic(title, content string, classID int64) error {
60+
func AddTopic(title, content string, classID int64) (int64, error) {
6161
o := orm.NewOrm()
6262
topic := &Topic{
6363
Title: title,
@@ -67,8 +67,8 @@ func AddTopic(title, content string, classID int64) error {
6767
ReplyTime: time.Now(),
6868
ClassID: classID,
6969
}
70-
_, err := o.Insert(topic)
71-
return err
70+
id, err := o.Insert(topic)
71+
return id, err
7272
}
7373

7474
// 获取所有文章

src/myblog/myblog

48 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)