dotws86260 2013-08-23 17:21
浏览 24
已采纳

为什么在symfony2中保存会话会删除我的属性?

This question is exactly as specified as above. I have code that looks like this:

// These attributes are getting deleted for some reason
$this->session->set('userProfiles',new ArrayCollection($uniqueList));

// Get array filter and save it in session
$this->session->set('filter',$filter);

// Save session
$this->session->save();

// The code bellow effects my attributes above. I don't know why that is.
$this->session->set('center',$center);
// If I comment the line bellow then attributes 'userProfile' and 'filter' do not get deleted
$this->session->save();

I am so beyond baffled as to why $this->session->save(); after setting my center attribute is actually deleting my data. Symfony does not have anything like this documented. It might have something to do with garbage collection, but I don't really know.

  • 写回答

1条回答 默认 最新

  • douyan1882 2013-08-23 21:49
    关注

    Things you put in the session must be serializable. ArrayCollection does not seem to implement the \Serializable interface.

    You can learn more about PHP session handling in the documentation:

    When PHP shuts down, it will automatically take the contents of the $_SESSION superglobal, serialize it, and send it for storage using the session save handler.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部