dotws86260 2013-08-24 01: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-24 05: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.

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

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画