0

This will change a variable in the session

$session = JFactory::getSession();
$session->set('name', "value");

But could you in the same way (directly) change any specific value of a session array?

0

I guess you mean to change the value of a key of a JSession property that is an array.

You have set your session property somewhere earlier

$session = JFactory::getSession();
$mySessionVar = array('a'=>'a', 'b'=>'b');
$session->set('mySessionVar', $mySessionVar);

Now you want to change that:

$session = JFactory::getSession();
// You get that property
$mySessionVar = $session->get('mySessionVar');

// It's an array. So you change the value for the array key
$mySessionVar['b'] = 'c';

// You set/update the same session variable
$session->set('mySessionVar', $mySessionVar);

// Now it holds the new data
$myNewSessionVar = $session->get('mySessionVar');

//echo '<pre>' . print_r($myNewSessionVar, true) . '</pre>';
1

Session data is stored as Registry. Use keys separated by a dot to access nested properties.

$session->set('array.key', 'value');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.