[eluser]southdevonwebdesign[/eluser]
I have a very confusing sessions problem with my application, I have an admin controller class which loads an orders model, in the order model it sets a variable called sortOrder which holds a SQL field to sort a database table. It also saves this to a session variable called sortOrder, which should be reloaded in the class constructor, however it flat refuses to take a variable as a value, it is however perfectly happy to take text. Am I missing something completely obvious with this?
Code
SortOrder function - saves the current order (doesn't save the session vars)
Code:
function sortOrderResults(){
if($this->uri->segment(4)!=""){
switch($this->uri->segment(4)){
case "orderRef":
$sort = 'a.orderRef';
break;
case "customerName":
$sort = 'b.firstName,b.lastName';
break;
case "dateCreated":
$sort = 'a.dateCreated';
break;
case "from_date":
$sort = 'a.from_date';
break;
case "to_date":
$sort = 'a.to_date';
break;
case "days":
$sort = 'a.days';
break;
case "valet":
$sort = 'a.valet';
break;
case "verified":
$sort = 'a.verified';
break;
case "status":
$sort = 'a.status';
break;
case "totalAmount":
$sort = 'a.totalAmount';
break;
}
if($this->sortResults==$sort){
if($this->orderResults == 'DESC'){
$this->orderResults = 'ASC';
}
else{
$this->orderResults = 'DESC';
}
}
$this->sortResults = $sort;
}
$this->session->set_userdata('sortResults',$this->sortResults);
$this->session->set_userdata('orderResults',$this->orderResults);
}
Class constructor - should read the session variable back in
Code:
var $sortResults = 'a.from_date';
var $orderResults = 'DESC';
function Model_order()
{
parent::Model();
if($this->session->userdata('sortResults'))
$this->sortResults = $this->session->userdata('sortResults');
if($this->session->userdata('orderResults'))
$this->orderResults = $this->session->userdata('orderResults');
}
This code works
Code:
function sortOrderResults(){
if($this->uri->segment(4)!=""){
switch($this->uri->segment(4)){
case "orderRef":
$sort = 'a.`orderRef`';
$this->session->set_userdata('sortResults','`a.orderRef`');
break;
case "customerName":
$sort = 'b.`firstName`,b.`lastName`';
$this->session->set_userdata('sortResults','b.`firstName`,b.`lastName`');
break;
case "dateCreated":
$sort = 'a.`dateCreated`';
$this->session->set_userdata('sortResults','a.`dateCreated`');
break;
case "from_date":
$sort = 'a.`from_date`';
$this->session->set_userdata('sortResults','a.`from_date`');
break;
case "to_date":
$sort = 'a.`to_date`';
$this->session->set_userdata('sortResults','a.`to_date`');
break;
case "days":
$sort = 'a.`days`';
$this->session->set_userdata('sortResults','a.`days`');
break;
case "valet":
$sort = 'a.`valet`';
$this->session->set_userdata('sortResults','a.`valet`');
break;
case "verified":
$sort = 'a.`verified`';
$this->session->set_userdata('sortResults','a.`verified`');
break;
case "status":
$sort = 'a.`status`';
$this->session->set_userdata('sortResults','a.`status`');
break;
case "totalAmount":
$sort = 'a.`totalAmount`';
$this->session->set_userdata('sortResults','a.`totalAmount`');
break;
}
if($this->sortResults==$sort){
if($this->orderResults == 'DESC'){
$this->orderResults = 'ASC';
$this->session->set_userdata('orderResults','ASC');
}
else{
$this->orderResults = 'DESC';
$this->session->set_userdata('orderResults','DESC');
}
}
$this->sortResults = $sort;
}
}