21294 Posts in 5734 Topics by 2602 members
|Go to End|
31 October 2009 at 3:19am
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)?
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
// 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)
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).
|Go to Top|