CodeIgniter Forums
CI 3 RC Session unset in associative array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: CI 3 RC Session unset in associative array (/showthread.php?tid=965)



CI 3 RC Session unset in associative array - summer - 02-01-2015

Hi There everyone!

I have recently upgraded my application to CI 3 RC because of CI's old sessions library, and there is an issue i would like to report.

i was using below structure previously to unset my userdata:

Code:
$user_data = array('admin_id' => '', 'username' => '', 'first_name' => '', 'last_name' => '', 'logged_in' => '');
$this->session->unset_userdata($user_data);

but its not working anymore on my project, its a simple backend for my websites. it was working before, i was on CI 3 Dev release before.

if i change code to below, then it works, issue is with the associative array:

Code:
$this->session->unset_userdata('admin_id');
$this->session->unset_userdata('username');
$this->session->unset_userdata('first_name');
$this->session->unset_userdata('last_name');
$this->session->unset_userdata('logged_in');

OR

Code:
$user_data = array('admin_id', 'username', 'first_name', 'last_name', 'logged_in');
$this->session->unset_userdata($user_data);

right now my project is on local system, i m using wamp on it, and its a windows 8.1 machine, i have tested in both latest chrome, and firefox.

i can give more details if needed, but i'm fairly new to the codeigniter. please pardon me if posted my first post in the wrong section or if this bug is already reported or if its already addressed.

Thanks.


RE: CI 3 RC Session unset in associative array - Narf - 02-02-2015

It's not a bug.


RE: CI 3 RC Session unset in associative array - summer - 02-02-2015

The documentation in CI 3RC is still stating first method of unsetting userdata to be valid, but its not working, so i think its a bug, if not and they have changed the way of unsetting userdata, documentation should be update as well.


RE: CI 3 RC Session unset in associative array - Narf - 02-02-2015

(02-02-2015, 02:19 AM)summer Wrote: The documentation in CI 3RC is still stating first method of unsetting userdata to be valid, but its not working, so i think its a bug, if not and they have changed the way of unsetting userdata, documentation should be update as well.

Seems like I've overlooked that change ... it's quite unintuitive, hence why I never thought of it.

https://github.com/bcit-ci/CodeIgniter/commit/b339df394b97b640df4a8745d16b94b4ee00e91e


RE: CI 3 RC Session unset in associative array - summer - 02-02-2015

As i have already mentioned i'm new to the codeigniter, thats why i was just trying to follow the documentation, i think i'm relying on it way to much, its not that much of correct or updated anyway. i will try to use more of my brain from now on. Smile

farewell.


RE: CI 3 RC Session unset in associative array - Narf - 02-02-2015

(02-02-2015, 05:25 AM)summer Wrote: As i have already mentioned i'm new to the codeigniter, thats why i was just trying to follow the documentation, i think i'm relying on it way to much, its not that much of correct or updated anyway. i will try to use more of my brain from now on. Smile

farewell.

You reported a valid issue, only it was a documentation issue and not a bug in the code. Doesn't mean that you shouldn't read the docs or that they are not otherwise correct.


RE: CI 3 RC Session unset in associative array - twpmarketing - 02-02-2015

(02-02-2015, 05:28 AM)Narf Wrote: You reported a valid issue, only it was a documentation issue and not a bug in the code. Doesn't mean that you shouldn't read the docs or that they are not otherwise correct.

@Narf  Will you state the doc correction here, please.  It will be some time before the doc gets corrected and passed down to us.

  Does the associative array session reset work with CI 3.0?  Based on the OP's result, it does not, but what is the "proper" method?  Must we write a multi-line reset instruction, one line for each variable?


RE: CI 3 RC Session unset in associative array - Narf - 02-02-2015

(02-02-2015, 09:25 AM)twpmarketing Wrote:
(02-02-2015, 05:28 AM)Narf Wrote: You reported a valid issue, only it was a documentation issue and not a bug in the code. Doesn't mean that you shouldn't read the docs or that they are not otherwise correct.

@Narf  Will you state the doc correction here, please.  It will be some time before the doc gets corrected and passed down to us.

  Does the associative array session reset work with CI 3.0?  Based on the OP's result, it does not, but what is the "proper" method?  Must we write a multi-line reset instruction, one line for each variable?

I've linked the commit 2 posts above.


RE: CI 3 RC Session unset in associative array - twpmarketing - 02-02-2015

Ok, thank you. For those who read this later, the doc change is as followed, quoted from the commit link:
Quote:Previously, this method used to accept an associative array of
+ ``'key' => 'dummy value'`` pairs for unsetting multiple keys. That
+ however makes no sense and you now have to pass *only* the keys, as
+ the elements of an array.
+
+ ::
+
+ // Old
+ $this->session->unset_userdata(array('item' => '', 'item2' => ''));
+
+ // New
+ $this->session->unset_userdata(array('item', 'item2'));



RE: CI 3 RC Session unset in associative array - Narf - 02-02-2015

(02-02-2015, 10:07 AM)twpmarketing Wrote: Ok, thank you. For those who read this later, the doc change is as followed, quoted from the commit link:

Quote:Previously, this method used to accept an associative array of
+ ``'key' => 'dummy value'`` pairs for unsetting multiple keys. That
+ however makes no sense and you now have to pass *only* the keys, as
+ the elements of an array.
+
+ ::
+
+ // Old
+ $this->session->unset_userdata(array('item' => '', 'item2' => ''));
+
+ // New
+ $this->session->unset_userdata(array('item', 'item2'));

If I was a reader, this post would insult me. I can click a link, I don't need somebody copy-pasting content around for me.