Welcome Guest, Not a member yet? Register   Sign In
How to set an array type session?
#1

[eluser]BnoL[/eluser]
Hi all,

I'm a new to CI, so please help me Big Grin

My question is: How can I set an array type session with CI?

My problem is I want to set array type session, just like:
Code:
$_SESSION['fruit'][] = "apple";
// code ...
// and then continue to add:
$_SESSION['fruit'][] = "banana";
...
in plain PHP. How can I do this with CI? Smile

Thanks in advance and sorry for my bad English Tongue
#2

[eluser]BnoL[/eluser]
I've tried
Code:
$this->session->set_userdata('fruit',array('apple','banana'));
var_dump($this->session->userdata('fruit'));

and the result is:

Code:
array(2) {
  [0]=>
  string(5) "apple"
  [1]=>
  string(6) "banana"
}

but how can I add more items to the array '$fruit'?

I've looked into class CI_Session , CI_Session:Confusedet_userdata() (Session.php) and it seems like CI doesn't have any method to handle my problem, does it?
#3

[eluser]bEz[/eluser]
You may have to get the array out of the session, apply changes as needed, and replace the session variable with the new data.
#4

[eluser]BnoL[/eluser]
[quote author="bEz" date="1246180842"]You may have to get the array out of the session, apply changes as needed, and replace the session variable with the new data.[/quote]

It'll take much time for performance, won't it?
If yes, I prefer to use standard PHP session ( $_SESSION ) instead of this. Sad




Theme © iAndrew 2016 - Forum software by © MyBB