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?