【发布时间】:2011-09-22 11:41:36
【问题描述】:
我知道我可以手动显式设置和取消设置会话,但我相信这值得一问。在 C# 中,有一个名为 TempData 的字典存储数据直到第一次请求。换句话说,当调用 TempData 时,它会自动取消设置。为了更好地理解这里是一个例子:
Controller1.cs:
TempData["data"] = "This is a stored data";
模型1.cs:
string dst1 = TempData["data"]; // This is a stored data
string dst2 = TempData["data"]; // This string will be empty, if an exception is not raised (I can't remember well if an exception is raised)
所以基本上,这只是一个仅供 1 次使用的会话。再次,我知道我可以在 php 中显式设置和取消设置,但是,php 是否有这样的功能?
【问题讨论】:
-
使用 $_SESSION。 PHP 中没有这样的 tempData。