CodeIgniter Forums
How to add session data without using set_userdata? The docs doesn't have an example. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: How to add session data without using set_userdata? The docs doesn't have an example. (/thread-81019.html)



How to add session data without using set_userdata? The docs doesn't have an example. - castle - 01-14-2022

Hi,
The documentation has an example of how to add data using set_userdata.
PHP Code:
$newdata = array(
        'username'  => 'johndoe',
        'email'    => '[email protected]',
        'logged_in' => TRUE
);

$this->session->set_userdata($newdata); 
But it says too "You can simply assign data to the $_SESSION array, as with any other variable. Or as a property of  $this->session."

Sorry, but I don't get it. How can I do that with the same example above without using set_userdata?

Cheers!


RE: How to add session data without using set_userdata? The docs doesn't have an example. - vimkaf - 01-14-2022

(01-14-2022, 05:22 AM)castle Wrote: Hi,
The documentation has an example of how to add data using set_userdata.
PHP Code:
$newdata = array(
        'username'  => 'johndoe',
        'email'    => '[email protected]',
        'logged_in' => TRUE
);

$this->session->set_userdata($newdata); 
But it says too "You can simply assign data to the $_SESSION array, as with any other variable. Or as a property of  $this->session."

Sorry, but I don't get it. How can I do that with the same example above without using set_userdata?

Cheers!

You can use the session helper 

PHP Code:
session()->set('key',$newdata

or 

PHP Code:
$_SESSION['key'] = $newdata 



RE: How to add session data without using set_userdata? The docs doesn't have an example. - castle - 01-14-2022

How about

PHP Code:
$this->session->language $language


Is it ok to do that?