Skip to content
Browse files

keep_flashdata accepts array

  • Loading branch information...
1 parent a815dbf commit 4beca5c9b64ba7bd1622e5c01666491f02cfa6db @johnathancroom johnathancroom committed Nov 23, 2012
Showing with 21 additions and 9 deletions.
  1. +18 −8 system/libraries/Session/Session.php
  2. +3 −1 user_guide_src/source/libraries/sessions.rst
View
26 system/libraries/Session/Session.php
@@ -389,18 +389,28 @@ public function set_flashdata($newdata = array(), $newval = '')
/**
* 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);
}
// ------------------------------------------------------------------------
View
4 user_guide_src/source/libraries/sessions.rst
@@ -195,18 +195,20 @@ 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();
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
========

0 comments on commit 4beca5c

Please sign in to comment.
Something went wrong with that request. Please try again.