Welcome Guest, Not a member yet? Register   Sign In
Updating a session array
#2

(This post was last modified: 02-01-2025, 06:22 AM by Sunchock.)

Hello Igniters,

Sorry to bring up such an old topic, I'm having the exact same problem.

I was wondering how to handle multi-level session variables using CodeIgniter?

For now, I'm using:
PHP Code:
// Initialization
session()->push('app1', ['subA' => []]);
// Creating a variable into app1/subA 
session('app1')['subA']['var01'] = "Such text"

But if I want to check elsewhere in the code if the var01 exists recursively, how do I achieve this?

PHP Code:
// For now, I use:
if (isset(session('app1') && isset(session('app1')['subA']) && isset(session('app1')['subA']['var01'])) 

// I would expect something like :
session('app1')->has('subA.var01');
// or
session()->has('app1.subA.var01'); 

Same problem if I want to delete subA but not others variables into app1 ?

PHP Code:
// For now, I use:
unset($_SESSION['app1']['subA']);

// I would expect something like :
session('app1')->remove('subA');
// or
session()->remove('app1.subA'); 


So I asked myself: am I doing things wrong?
I mean: what are the best practices for handling session subvariables?
Reply


Messages In This Thread
Updating a session array - by Qodi - 10-19-2018, 12:35 PM
RE: Updating a session array - by Sunchock - 01-31-2025, 04:25 AM
RE: Updating a session array - by luckmoshy - 01-31-2025, 09:59 AM
RE: Updating a session array - by InsiteFX - 01-31-2025, 11:35 PM
RE: Updating a session array - by Sunchock - 02-01-2025, 06:29 AM
RE: Updating a session array - by ozornick - 02-04-2025, 12:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB