Welcome Guest, Not a member yet? Register   Sign In
Will Sessions be the death of me?
#1

[eluser]Solarpitch[/eluser]
...Possibly. I cant figure this out at all. I dont think sessions is well documented in the user guide for a start. I'm setting a session in one function in my controller, then simply trying to get the value of it in another... but it's empty.

However it works when I set and retrieve the session in the same function which doesn't make sence.

Code:
function report_charts(){
$this->load->library('session');

$date = $this->session->set_userdata('chart_set_date', '20090106');

}

function graph(){

$this->load->library('session');
$this->load->model('report_model');
$this->load->helper('graph');

//call the session ans pass the value to the model. The value is empty
$date = $this->session->userdata('chart_set_date');
$sales_breakdown_chart = $this->report_model->sales_breakdown_chart($date);

$date = "20090106";

}

Settings...


Code:
$config['sess_cookie_name']        = 'ci_session';
$config['sess_expiration']        = 7200;
$config['sess_encrypt_cookie']    = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']        = 'sessions';
$config['sess_match_ip']        = TRUE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']     = 300;

$config['cookie_prefix']    = "";
$config['cookie_domain']    = ".mysite.com";
$config['cookie_path']        = "/";

$config['base_url']    = "http://mysite.com/enterprise/";
#2

[eluser]Anthony Hull[/eluser]
Have you tried using sessions the old fashioned way?

$_SESSION['name'] = 'test';

echo($_SESSION['name']);
#3

[eluser]drewbee[/eluser]
report_charts() is being called before graph, correct?
#4

[eluser]Solarpitch[/eluser]
Hi, yeah report_charts is being called first to set the date. Then the graph is called and I simply want to use the session to pop in the set date for the graph.

@Anthony Hull ... I'd rather use the CI session as I dotn want to be usign a mix of both throughout the application.. would get a little messy.
#5

[eluser]Solarpitch[/eluser]
Anyone want to try and help with this? Been almost a week now trying to sort this out... bringing my project to a stand stil
#6

[eluser]GSV Sleeper Service[/eluser]
CI sessions are cookie based, so you could set it in one function, and it WONT be available in the other function unless a new page has been loaded. (cookies can only be set by sending a header to your browser)
Look up 'native sessions' in the wiki, and install that, you won't have to change your code, and sessions will work as you expect them to work.
#7

[eluser]srisa[/eluser]
If the 'char_set_date' is to be used only in the given controller/model/library, you are better off using a private member variable.
Shouldn't you be auto-loading the sessions library? That may not be the issue though.




Theme © iAndrew 2016 - Forum software by © MyBB