Welcome Guest, Not a member yet? Register   Sign In
Keep ALL flashdata?
#1

[eluser]sheldonnbbaker[/eluser]
I have an asset controller which loads my CSS, JS, and PNGs (there isn't any direct access to the .css, .js, or .png files).

However, this messes up any flashdata stuff - so if I set_flashdata('foo, 'bar') in my controller, it'll die in the next server request of course, which just so happens to be my asset controller.

So, instead of doing this:

Code:
keep_flashdata('item1');
keep_flashdata('item2');
keep_flashdata('item3');

I'd like to just do this:

Code:
keep_flashdata();
#2

[eluser]solepixel[/eluser]
Not sure if you ever found a solution for this, but I wrote this in order to hang onto any flashdata during a 301 redirect. Hope it works for you Smile

Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class EXT_Session extends CI_Session {
    /**
     * Keeps existing flashdata available to next request.
     *
     * @access    public
     * @param    string
     * @return    void
     */
    function keep_flashdata($key=NULL)
    {
        // 'old' flashdata gets removed.  Here we mark all
        // flashdata as 'new' to preserve it from _flashdata_sweep()
        // Note the function will NOT return FALSE if the $key
        // provided cannot be found, it will retain ALL flashdata
        
        if($key === NULL){
            foreach($this->userdata as $k => $v){
                $old_flashdata_key = $this->flashdata_key.':old:';
                if(strpos($k, $old_flashdata_key) !== false){
                    $new_flashdata_key = $this->flashdata_key.':new:';
                    $new_flashdata_key = str_replace($old_flashdata_key, $new_flashdata_key, $k);
                    $this->set_userdata($new_flashdata_key, $v);
                }
            }
            return true;
            
        } elseif(is_array($key)){
            foreach($key as $k){
                $this->keep_flashdata($k);
            }
        }
        
        $old_flashdata_key = $this->flashdata_key.':old:'.$key;
        $value = $this->userdata($old_flashdata_key);

        $new_flashdata_key = $this->flashdata_key.':new:'.$key;
        $this->set_userdata($new_flashdata_key, $value);
    }
    
}




Theme © iAndrew 2016 - Forum software by © MyBB