tags:

views:

30

answers:

1

for example i have Session::instance()->get('orders') which is an array of some arrays:

$first = array('id' = 1, 'name' => 'first', 'price' => 100); $second = array('id' => 2, 'name' => 'second', 'price' => 200); $_SESSION['orders'] = array($first, $second);

but if i use this

Session::instance()->set('orders', array(array('id' => 3, 'name' => 'third', 'price' => 300)));

this will erase first orders (id 1, id 2). so how can i ADD but not ERASE data arrays to session array named 'orders'? array_push or something else?

+1  A: 

Edit, didn't see your comment, it's perfect.

Self explanatory.

$session = Session::instance();

// Find existing data
$data = $session->get('orders');

// Add new array
$data[] = array('id' => 3, 'name' => 'new data', 'price' => 300);

// Resave it
$session->set('orders', $data);
The Pixel Developer
also i found that we can initialize $_SESSION array and use it as in raw php code.i mean to link Session::instance() to $_SESSIOn array because in kohana we can't manipulate with $_SESSION array directly by default.
purple

related questions