1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XenForo_Session question...

Discussion in 'XenForo Development Discussions' started by Mr. Goodie2Shoes, Dec 6, 2012.

  1. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    Well, at this moment, I am using cookies to save an instance. And for some reason I can't save it in the session by:
    and when I 'fetch' it by:
    I am getting 'false' instead of the instance.
  2. Chris D

    Chris D XenForo Developer Staff Member

    I get this when I try and set a value using getSession()->set:

    An exception occurred: The session has been saved and is now read-only

    I've never really used the session before so not sure how to fix this, but have you considered either using the Data Registry or Simple Cache?
  3. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    Well, I need to save the data on one page and show it on another, so 'caches' wont work...
    you have to do it either by creating sessions, save it in the Db or save it as a cookie...
  4. Chris D

    Chris D XenForo Developer Staff Member

    The caches would work for that.

    You will want to make sure you remove the data once you're finished with it:

    (Values of false will remove the cached data)
    Jake Bunce and Mr. Goodie2Shoes like this.
  5. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    I thought it was a 'simple' cache... now that you mentioned it, I checked the details and it says the data is cached persistently... so I guess this is what I was looking for. Thanks! :D
  6. digitalpoint

    digitalpoint Well-Known Member

    If the data is something you don't use every page view, the cache is the best place for it. But as a side note, just in case someone runs across this problem where they want to save session data (and it's the best place for it)... you just need to set session data earlier in the request. For example, when I do stuff with the session, it's typically done within a "controller_pre_dispatch" event listener. At that point setting session variables is perfectly okay since the session hasn't been saved yet.
  7. Chris D

    Chris D XenForo Developer Staff Member

    That's a great suggestion! (y)

Share This Page