21294 Posts in 5734 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 838 Views |
-
Session Class

31 October 2009 at 3:19am
Hi All,
Does anyone have any good docs/tutorials on working with the session class? There is not a lot I can find, and the API reference says it may be being depreciated.
Is this the case? Because the forms still seem to run off them (for error messages and what not)?
Cheers,
Mo
-
Re: Session Class

31 October 2009 at 4:11am Last edited: 31 October 2009 4:12am
I have worked extensively with them and this is an area where the SS team has done an excellent job at abstracting them. So much in fact there really isn't much to document.
$x = 'remember this';
$y = array('some' => 'stuff', 'nest' => array('of'=>'other'));
$z = DataObject::get_by_id('Page',43);// Save stuff in the session
Session::set('Identifier.X',$x);
Session::set('MyLongIdString', serialize($y));
Session::set('ThatPage', serialize($z));// Fetch them back, some other page load, some other day
$newX = Session::get('Identifier.X');
$newY = unserialize(Session::get('MyLongIdString'));
$newZ = unserialize(Session::get('ThatPage'));// Don't really put objects like $z in session,
// it makes them way heavy and they'll chew up
// a ton of resources as they have to be loaded from
// disk every time a page is served (depending on
// your PHP session storage settings)
Session::clear('ThatPage');Thats all there really is to it. Create a unique identifier string and set/get. You will have that data persistently available until the session expires. Do make a habit of keeping it cleaned up because it can get expensive to load/save huge sessions.
Also remember to serialize/unserialize any complex objects (like anything not a string).
| 838 Views | ||
|
Page:
1
|
Go to Top |


