Welcome Guest, Not a member yet? Register   Sign In
Problem with getting value from a Session.
#1

[eluser]Solarpitch[/eluser]
Hey,

I'm assigning a value of a date to a session and then trying to retrieve the value of it in another controller function. Here's a cut down version of what I have... seems pretty basic to me.

Code:
class Enterprise extends Controller {

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


function dashboard(){

$year = $this->uri->segment(3);
$month = $this->uri->segment(4);
$day = $this->uri->segment(5);

//SET THE DATE IN FORMAT OF '20090301' THEN ASSIGN TO SESSION 'report_date'
$date = $year.$month.$day;
$this->session->set_userdata('report_date', $date);
}

function sales_breakdown(){

//GET VALUE OF THE SESSION TO PASS TO A DB QUERY

$date = $this->session->userdata('report_date');
$data['sales'] = $this->report_model->sales_breakdown($date);

//THIS WILL BASICALLY RUN THE QUERY BUT WILL LEAVE THE DATE BLANK.

}
It seems to work if I was to hard code setting the session in the sales_breakdown function. Is this a know problem or something because it seems to be by the book.
#2

[eluser]Solarpitch[/eluser]
Hey... just wondering if anyone could help with this. It's just I'm a little overdue my project deadline and getting these session sorted will get me sorted Smile
#3

[eluser]obiron2[/eluser]
I would suspect that it is a date format issue.

What format is the date stored in in your database or do you convert it in the report_model before you use it.

try changing $date to str($year).str($month).str($day)


Obiron
#4

[eluser]Solarpitch[/eluser]
Thanks for your reply man. That seems to work now, the only problem is the session wont rewrite itself when it's passed a new value, it just seems to store the initial value it was first set. Even if I try to unset it before the new one is set...

Code:
//unset the current session
$this->session->unset_userdata('report_date');

//now get date and reset
$date = str($year).str($month).str($day);
$this->session->set_userdata('report_date', $date);

.. it still keeps the very first date it was assigned.
#5

[eluser]Solarpitch[/eluser]
Actually, This doesnt work... str($year).str($month).str($day);
but this is whats happening
Code:
//if I set date like this the session will reset itself to this date
$date = '20090113';

//if I try to set it like this it wont reset and it's value will stay the same
$date = $year.$month.$day;


$this->session->set_userdata('report_date', $date);

I dont understand this, $year.$month.$day; is basically being set as 20090113 the same as when I had code it. So why is that making a difference when it comes to setting this session.




Theme © iAndrew 2016 - Forum software by © MyBB