[eluser]dynZack[/eluser]
For the last hour I've been trying to save some $_POST variables to $_SESSION, so that they are available in subsequent requests.
Basically the user applies some filters to some query results and the results are displayed page-by-page using the pagination class.
I want to save these filter variables so that the query is not destroyed when viewing the 2nd,3rd... page.
Here is what I'm doing in the controller:
Code:
$active_filters = FALSE;
if ($this-> input-> post('submit')){//User has filtered results
unset($_SESSION);
$active_filters = TRUE;
}
elseif ( !empty($_SESSION) ){//Previous filters exist
echo"session";
$_POST = $_SESSION;
$active_filters = TRUE;
}
echo isset($_SESSION);
if ($active_filters){
$parent_fields = $this->config->item($this->activeSEF['parent_category'], 'fields');
$fields = $this->config->item($this->activeSEF['category'], 'fields');
foreach ($parent_fields as $field){
if (!in_array($field,$fields)){
if ($this-> input-> post($field)){
$filters[$field] = $this-> input-> post($field);
}
}
}
if (is_numeric($this-> input-> post('price_low'))){
$filters['price_low'] = $this-> input-> post('price_low');
}
if (is_numeric($this-> input-> post('price_high'))){
$filters['price_high'] = $this-> input-> post('price_high');
echo $filters['price_high'];
}
$_SESSION = $_POST;
}
First the controller checks if the user has submitted the FILTER form. If not, it checks if $_SESSION is not empty (which means that filter variables were set in a previous script) and copies the contents into $_POST. At the end of if ($active_filters){} the $_SESSION is updated with the contents of $_POST.
Ok, there are lot of issues with this approach, but still it should work and retrieve the correct results. However it doesn't: the filters are not applied when viewing the 2nd, 3rd,... pages.
Any ideas or a different approach?