Beispiel #1
0
func (this *MainController) Get() {
	this.Data["Css"] = conf.GetCss()
	this.Data["Js"] = conf.GetJs()

	user := models.NewUser()
	err := user.FindById(int(1))
	if err != nil {
		beego.Error(err)
		return
	}

	data, err := user.GetInitialData()
	if err != nil {
		beego.Error(err)
	}

	str, err := json.Marshal(map[string]interface{}{"init": data})
	if err != nil {
		beego.Error(err)
	}

	this.Data["Storage"] = template.JS(string(str))

	this.TplNames = "/index.tpl"
	return
}
Beispiel #2
0
func (this *UserController) Get() {
	var id int
	this.Ctx.Input.Bind(&id, "id")

	if id <= 0 {
		this.Data["json"] = errors.New("User id is required")
		this.ServeJson()
		return
	}

	user := models.NewUser()
	err := user.FindById(id)
	if err != nil {
		beego.Error(err)
	}

	this.Data["json"] = user

	this.ServeJson()
}