Exemple #1
0
func (this *TestController) Index() {
	// model := web.D(new(TestModel))
	model := &UserModel{}
	// model.DBPrifix = "PG"
	// model := NewPgUser()
	web.D(model, "PG")
	// aolog.Info(model.Insert(map[string]interface{}{"name": "test"}))
	// aolog.Info(model.Where("id=?", 1).Update(map[string]interface{}{"name": "test1"}))
	// aolog.Info(model.Where("id=?",16).Delete())
	// aolog.Info(model.Query("select * from user"))
	// aolog.Info(model.Where("id=?",1).Find())
	// aolog.Info(model.Total())
	// aolog.Info(model.Where("id=?",1).Total())
	aolog.Info(model.Order("id desc").Select())
	if user, ok := this.Form["user"]; ok {
		this.SetSession("user", user)
	}
	aolog.Info(this.Data)
	tmp := make(map[string]interface{})
	tmp["a"] = 1
	tmp["b"] = "jom"
	this.WriteJson(tmp)
	// this.WriteString("artwebs")
	// this.WriteString("artwebs1")
}
Exemple #2
0
func (this *IndexController) Normal() {
	if err := this.verfiySession(); err != nil {
		this.write(data_error(err.Error()))
		return
	}
	model := &DefaultModel{}
	web.D(model)
	key := this.UrlVal[0]
	this.write(model.Aws(key, this.Form))
}
Exemple #3
0
func (this *IndexController) Index() {
	this.UrlKey = this.UrlVal[:]
	router := "/" + strings.Join(this.UrlKey, "/")
	_, obj := routerTree.FindRouter(router)
	if obj != nil {
		val := obj.(*Router)
		if !this.verfiySession(val.Session) {
			return
		}
		model := &DefaultModel{}
		web.D(model)
		if val.Data != nil {
			for key, value := range val.Data {
				switch value {
				case "SaveFile":
					file, err := this.SaveToFile("File", "")
					if err == nil {
						this.Data[key] = map[string]interface{}{"code": 1, "message": "上传成功", "result": file}
					} else {
						this.Data[key] = map[string]interface{}{"code": 0, "message": err, "result": ""}
					}

					break
				case "VerfiyCode":
					d := make([]byte, 4)
					s := utils.NewLen(4)
					ss := ""
					d = []byte(s)
					for v := range d {
						d[v] %= 10
						ss += strconv.FormatInt(int64(d[v]), 32)
					}
					this.SetSession(key, ss)
					this.WriteImage(utils.NewImage(d, 100, 40))
					return
				case "DownloadFile":
					log.InfoTag(this, "DownloadFile", strings.TrimPrefix(router, "/"))
					this.ServeFile(strings.TrimPrefix(router, "/"))
					return
				default:
					this.Data[key] = model.Aws(value, this.Form)
				}

			}
		}
		this.doSession(val.Session)
		tpl := router
		if val.Tpl != "" {
			tpl = val.Tpl
		}
		this.Data["req"] = this.Form
		if _, err := os.Stat(this.Template(tpl)); err == nil {
			this.Display(tpl)
		} else {
			this.WriteJson(this.Data)
		}

	} else {
		this.WriteString(router + " do not find!")
	}

}