From 4beca5c9b64ba7bd1622e5c01666491f02cfa6db Mon Sep 17 00:00:00 2001 From: Johnathan Croom Date: Fri, 23 Nov 2012 18:32:46 -0700 Subject: keep_flashdata accepts array --- system/libraries/Session/Session.php | 26 ++++++++++++++++++-------- user_guide_src/source/libraries/sessions.rst | 4 +++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 96e65f154..81d63c304 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -389,18 +389,28 @@ class CI_Session extends CI_Driver_Library { /** * Keeps existing flashdata available to next request. * - * @param string Item key + * @param mixed Item key * @return void */ - public function keep_flashdata($key) + public function keep_flashdata($data) { - // 'old' flashdata gets removed. Here we mark all flashdata as 'new' to preserve it from _flashdata_sweep() - // Note the function will return NULL if the $key provided cannot be found - $old_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key; - $value = $this->userdata($old_flashdata_key); + // Wrap item as array if singular + if (is_string($data)) + { + $data = array($data); + } + + foreach($data as $key) + { + // 'old' flashdata gets removed. Here we mark all flashdata as 'new' to preserve it from _flashdata_sweep() + // Note the function will return NULL if the $key provided cannot be found + $old_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key; + $value = $this->userdata($old_flashdata_key); + + $new_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key; + $this->set_userdata($new_flashdata_key, $value); + } - $new_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key; - $this->set_userdata($new_flashdata_key, $value); } // ------------------------------------------------------------------------ diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index ee7fb0b1c..aecad3164 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -195,7 +195,7 @@ set_userdata(). To read a flashdata variable:: $this->session->flashdata('item'); - + An array of all flashdata can be retrieved as follows:: $this->session->all_flashdata(); @@ -203,10 +203,12 @@ An array of all flashdata can be retrieved as follows:: If you find that you need to preserve a flashdata variable through an additional request, you can do so using the keep_flashdata() function. +You can either pass a single item or an array of flashdata items to keep. :: $this->session->keep_flashdata('item'); + $this->session->keep_flashdata(array('item1', 'item2', 'item3')); Tempdata ======== -- cgit v1.2.3-24-g4f1b From 9d9849b2c459cb09ccebcdf89b2b3a15bc4fd722 Mon Sep 17 00:00:00 2001 From: Johnathan Croom Date: Sat, 24 Nov 2012 13:03:13 -0700 Subject: Requested changed to keep_flashdata --- system/libraries/Session/Session.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 81d63c304..910b99936 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -389,18 +389,18 @@ class CI_Session extends CI_Driver_Library { /** * Keeps existing flashdata available to next request. * - * @param mixed Item key + * @param mixed Item key(s) * @return void */ public function keep_flashdata($data) { // Wrap item as array if singular - if (is_string($data)) + if (!is_array($data)) { $data = array($data); } - foreach($data as $key) + foreach ($data as $key) { // 'old' flashdata gets removed. Here we mark all flashdata as 'new' to preserve it from _flashdata_sweep() // Note the function will return NULL if the $key provided cannot be found @@ -410,7 +410,6 @@ class CI_Session extends CI_Driver_Library { $new_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key; $this->set_userdata($new_flashdata_key, $value); } - } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 8d8543da992985ae61a6903a138d949f189721e9 Mon Sep 17 00:00:00 2001 From: Johnathan Croom Date: Sun, 25 Nov 2012 10:36:57 -0700 Subject: Improved array keey_flashdata + Changelog --- system/libraries/Session/Session.php | 28 +++++++++++++++------------- user_guide_src/source/changelog.rst | 1 + 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 910b99936..9b011dea3 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -392,24 +392,26 @@ class CI_Session extends CI_Driver_Library { * @param mixed Item key(s) * @return void */ - public function keep_flashdata($data) + public function keep_flashdata($key) { - // Wrap item as array if singular - if (!is_array($data)) - { - $data = array($data); - } - foreach ($data as $key) + if (is_array($key)) { - // 'old' flashdata gets removed. Here we mark all flashdata as 'new' to preserve it from _flashdata_sweep() - // Note the function will return NULL if the $key provided cannot be found - $old_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key; - $value = $this->userdata($old_flashdata_key); + foreach ($key as $k) + { + $this->keep_flashdata($k); + } - $new_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key; - $this->set_userdata($new_flashdata_key, $value); + return; } + + // 'old' flashdata gets removed. Here we mark all flashdata as 'new' to preserve it from _flashdata_sweep() + // Note the function will return NULL if the $key provided cannot be found + $old_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key; + $value = $this->userdata($old_flashdata_key); + + $new_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key; + $this->set_userdata($new_flashdata_key, $value); } // ------------------------------------------------------------------------ diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index a20cd10f2..cfed49c6f 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -198,6 +198,7 @@ Release Date: Not Released - Added ``all_flashdata()`` method to session class. Returns an associative array of only flashdata. - Added ``has_userdata()`` method to verify existence of userdata item. - Added ``tempdata()``, ``set_tempdata()``, and ``unset_tempdata()`` methods for manipulating tempdata. + - ``keep_flashdata()`` now accepts an array of values. - :doc:`File Uploading Library ` changes include: - Added *max_filename_increment* config setting. - Added an "index" parameter to the ``data()`` method. -- cgit v1.2.3-24-g4f1b From 3892995d21bc030ef8f6389abe1669d34c954ccd Mon Sep 17 00:00:00 2001 From: Johnathan Croom Date: Sun, 25 Nov 2012 14:08:24 -0700 Subject: Changelog change --- user_guide_src/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index cfed49c6f..5d4757a7e 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -198,7 +198,7 @@ Release Date: Not Released - Added ``all_flashdata()`` method to session class. Returns an associative array of only flashdata. - Added ``has_userdata()`` method to verify existence of userdata item. - Added ``tempdata()``, ``set_tempdata()``, and ``unset_tempdata()`` methods for manipulating tempdata. - - ``keep_flashdata()`` now accepts an array of values. + - ``keep_flashdata()`` now accepts an array of keys. - :doc:`File Uploading Library ` changes include: - Added *max_filename_increment* config setting. - Added an "index" parameter to the ``data()`` method. -- cgit v1.2.3-24-g4f1b