Beispiel #1
0
func (this *TopicController) LoadView() {
	tid := this.Input().Get("tid")

	var topic *(models.Topic)
	var err error
	switch beego.AppConfig.String("database") {
	case "redis":
		topic, err = models.GetTopicRedis(tid)
	default:
		topic, err = models.GetTopic(tid)
	}

	if err != nil {
		beego.Error(err)
		this.Redirect("/", 302)
		return
	}

	var replies []*(models.Reply)
	switch beego.AppConfig.String("database") {
	case "redis":
		replies, err = models.GetAllRepliesRedis(tid)
	default:
		replies, err = models.GetAllReplies(tid)
	}

	if err != nil {
		beego.Error(err)
		return
	}

	data := &struct {
		Topic   *models.Topic
		Lables  []string
		Replies []*models.Reply
	}{
		Topic:   topic,
		Lables:  strings.Split(topic.Lables, " "),
		Replies: replies,
	}

	this.Data["json"] = data
	this.ServeJson()
}
Beispiel #2
0
func (this *TopicController) LoadModify() {

	tid := this.Input().Get("tid")

	var topic *(models.Topic)
	var err error
	switch beego.AppConfig.String("database") {
	case "redis":
		topic, err = models.GetTopicRedis(tid)
	default:
		topic, err = models.GetTopic(tid)
	}

	if err != nil {
		beego.Error(err)
		this.Redirect("/", 302)
		return
	}

	this.Data["json"] = &topic
	this.ServeJson()

}