Skip to content

Commit 7702fe9

Browse files
committed
session例子
1 parent 4a0c802 commit 7702fe9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

14.2.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ beego中主要有如下这些全局变量来控制session处理:
5555
## session使用
5656
通过上面的代码我们可以看到,beego框架很方便的就继承了session功能,那么我们在项目中如何使用呢?请看的示例代码:
5757

58+
func (this *MainController) Get() {
59+
var intcount int
60+
sess := this.StartSession()
61+
count := sess.Get("count")
62+
if count == nil {
63+
intcount = 0
64+
} else {
65+
intcount = count.(int)
66+
}
67+
intcount = intcount + 1
68+
sess.Set("count", intcount)
69+
this.Data["Username"] = "astaxie"
70+
this.Data["Email"] = "[email protected]"
71+
this.Data["Count"] = intcount
72+
this.TplNames = "index.tpl"
73+
}
74+
75+
上面的代码展示了如何在我们自己的控制逻辑中使用session,主要分两个步骤:
76+
77+
1. 获取session对象
78+
79+
2. 使用session进行一般的session值操作
5880

5981

6082

0 commit comments

Comments
 (0)