XenForo_Session question...

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:
PHP:
XenForo_Application::getSession()->set($key, $value)

and when I 'fetch' it by:
PHP:
XenForo_Application::getSession()->get($key)
I am getting 'false' instead of the instance.
 
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?
 
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...
 
The caches would work for that.

PHP:
XenForo_Application::setSimpleCacheData($key, $value);
 
XenForo_Application::getSimpleCacheData($key);

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

PHP:
XenForo_Application::setSimpleCacheData($key, false);

(Values of false will remove the cached data)
 
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
 
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.
 
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.
That's a great suggestion! (y)
 
Top Bottom