Welcome Guest, Not a member yet? Register   Sign In
keep_flashdatabug ?
#1

[eluser]Ricola[/eluser]
hi there

i'm trying to use session library everything seems good except " keep_flashdata "

i wrote a simple code by using keep_flashdata to store my session data like a code below :

class Test extends MY_Controller {

Code:
function __construct()
{
     parent::__construct();
     $this->load->library('session');
}

function index()
{
     $this->session->set_flashdata('delivery','this is flash delivery');
     $this->session->keep_flashdata('delivery');
     echo 'flash data set';
}

function test1()
{
     echo $this->session->flashdata('delivery');
}
    
function test2()
{
     echo $this->session->flashdata('delivery');
}

}

the point is every method in test controller (test1,test2) doesn't show up anything i don't know what exactly reason

but if i remove or comment " keep_flashdata " everything works fine.

I think it is a simple code for test , so it would not happen by my mistake


thank you
I'm using codeigniter 2.0(official)
PHP 5.2.6
Complied by my own computer (Windows 7)
#2

[eluser]Cristian Gilè[/eluser]
Quote:CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared....If you find that you need to preserve a flashdata variable through an additional request, you can do so using the keep_flashdata() function.

Your code is good but you are using flashdata in the wrong way.
Copy this code and type http://yourwebsite/index.php/test


Code:
class Test extends MY_Controller {

function __construct()
{
     parent::__construct();
     $this->load->library('session');
     $this->load->helper('url');
}

function index()
{
     //we set the flash data
     $this->session->set_flashdata('delivery','this is flash delivery');
     redirect('test/test1');
}


function test1()
{
     //after the first redirect we keep the flash data for the next request otherwise the flashdata is destroied
     $this->session->keep_flashdata('delivery');
     redirect('test/test2');
}
    
function test2()
{
     //print the flashdata content
     echo $this->session->flashdata('delivery');
}

}


Cristian Gilè
#3

[eluser]Ricola[/eluser]
thank you ,Cristian

it helps !!
#4

[eluser]Ricola[/eluser]
well, this is codeigniter forum i don't think it is java




Theme © iAndrew 2016 - Forum software by © MyBB