/
topic.go
executable file
·58 lines (52 loc) · 1.28 KB
/
topic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package controllers
import (
"cwengo.com/models"
"github.com/astaxie/beego"
/*"strconv"*/
"strings"
)
type TopicController struct {
beego.Controller
}
type MyLabel struct {
Name string
Id string
}
func (this *TopicController) Get() {
topicId := this.Input().Get("topicId")
if topicId == "" {
this.TplNames = "error.html"
} else {
topic, err := models.GetTopic(topicId)
if err != nil {
beego.Error(err)
this.Redirect("/", 302)
return
}
this.Data["Topic"] = topic
this.Data["Category"] = models.GetCategory(topic.Category)
//AllLabels := make([]string, 10)
Lables := strings.Split(topic.Lables, " ")
var MyLables []MyLabel
if len(Lables) > 0 {
for i, n := 0, len(Lables); i < n; i++ {
//AllLabels[i] = models.GetLabel(Lables[i])
LabelOne := MyLabel{
Name: models.GetLabel(Lables[i]),
Id: Lables[i],
}
MyLables = append(MyLables, LabelOne)
}
//this.Data["LablesId"] = Lables[0:len(Lables)]
}
this.Data["Label"] = MyLables
if err != nil {
beego.Error(err)
}
this.Data["Categories"], _ = models.GetAllCategories()
this.Data["Labels"], err = models.GetAllLabels()
this.Data["NewTopics"], err = models.GetAllNewTopics()
this.Data["VIewsTopics"], err = models.GetAllViewsTopics()
this.TplNames = "topicView.html"
}
}