Working with $_SESSION

It is important that the $_SESSION array is segmentented for every class that uses it. This is to avoid collisions with variable names. Solar_Session does this for you. You instantiate Solar_Session telling it what you want to call your segment in $_SESSION array. You can then read and write values from the $_SESSION segment.

<?php
// get a session segment for class Vendor_Example
$session = Solar::factory(
    'Solar_Session',
    array('class' => 'Vendor_Example')
);

// $session->store is now a reference to $_SESSION['Vendor_Example']

// this...
$session->set('name', 'value');

// ...is same as this...
$session->store['name'] = 'value';

// ...which is also same as this...
$_SESSION['Vendor_Example']['name'] = 'value';
?>

session_start() is called once you instantiate the Solar_Session object.

 
manual/sessions/session_vars.txt · Last modified: 2008/08/25 08:48 (external edit)