[eluser]Aken[/eluser]
You can set userdata in two ways:
1) Individually:
Code:
$this->session->set_userdata('name', 'Mike');
2) Multiple items at once, via array:
Code:
$data = array(
'name' => 'Mike',
'age' => 26,
'city' => 'Milwaukee',
);
$this->session->set_userdata($data);
I'm simply offering a suggestion of storing data in a way that makes it easier to access in your application. If you store all of your 20+ info items via the array method #2, each one will be accessed via the following:
Code:
echo $this->session->userdata('name');
echo $this->session->userdata('age');
Instead, if you take all those items and put them inside an array or object, and then serialize it, you will effectively have a single string with a ton of data in it.
Code:
$info = (object) array(
'name' => 'Mike',
'age' => 26,
'city' => 'Milwaukee',
);
$this->session->set_userdata('info', serialize($info));
Then, you can call that single item, assign it to a variable in your controller, and then access each item with MUCH less code.
Code:
$info = unserialize($this->session->userdata('info'));
echo $info->name;
echo $info->age;
The downside to this method is if you want to update one of those properties, you have to update your array/object, serialize it again then set the session data again. So you might not want to use it for flags such as if they're logged in or any other user data that might be dynamic while they are using your application.