Symfony 1.4 中的会话删除 [英] Session deletion in Symfony 1.4
问题描述
如果会话变量不在数组中,如何一次删除它们?
How do I delete all session variables at once if they are not in Array?
PS 我是这样设置的:
PS I set them this way:
$this->getUser()->setAttribute('PayPalTransaction.hash', $request->getParameter('hash'));
问候,罗马
推荐答案
sfUser
类(通过 $this->getUser()
获得),保持sfNamespacedParameterHolder
中的所有属性.所以 sfUser
上的 setAttribute()
函数只是 sfNamespacedParameterHolder::setAttribute()
的代理.您可以使用 sfUser::getAttributeHolder()
获取对此持有者的引用.
The sfUser
class (which you get with $this->getUser()
), keeps all it's attributes in a sfNamespacedParameterHolder
. So the setAttribute()
function on sfUser
if merely a proxy to the sfNamespacedParameterHolder::setAttribute()
. You can get the reference to this holder with sfUser::getAttributeHolder()
.
sfNamespacedParameterHolder
还有一个函数 clear()
,用来清除所有的属性.
The sfNamespacedParameterHolder
also has a function clear()
, which clears all attributes.
所以要清除所有属性,请使用:$this->getUser()->getAttributeHolder()->clear()
.
So to clear all attributes, use:
$this->getUser()->getAttributeHolder()->clear()
.
(请注意,当您清除属性持有者时,您仍将通过身份验证(例如登录).
(Please note that you will still be authenticated (e.g. logged in) when you clear the attribute holder).
这篇关于Symfony 1.4 中的会话删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!