CodeIgniter Forums
Simple function to get all the flashdata - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Simple function to get all the flashdata (/showthread.php?tid=29490)



Simple function to get all the flashdata - El Forum - 04-11-2010

[eluser]Unknown[/eluser]
hi, need to get just the flashdata?
(maybe useful to repopulate a form if you store all your $_POST in flashdata session)
here a simple php script in a custom Session Class
(CI -version 1.7.2)
any suggestion is appreciated
Mirko
Code:
class MY_Session extends CI_Session {
function  __construct() {
  parent::CI_Session();
}

/**
  * Gets all the flashdata stored in CI session
  *
  * @author Mirko Mariotti
  * @return Array The flashdata array
  */
function all_flashdata() {
  $all_flashdata=$res=array();
  foreach($this->all_userdata() as $k=>$v) {
   if(preg_match('/^flash:old:(.+)/', $k, $res)) {
    $all_flashdata[$res[1]] = $this->userdata($this->flashdata_key.':old:'.$res[1]);
   }
  }
  return $all_flashdata;
}

greetings