• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing filter settings - combining http-post values, session-values, and default-values

Hi there CodeIgniter community! Smile

I am having trouble finding the most suited way to deal with the following problem;

In my view I would like to present a list of checkboxes so that the user can enable/disable a certain filter setting.

When sent to my controller (using post) I need to set some session-data which I can use when calling my model to activate the chosen settings.

Pretty straight forward for now.. But then the question is: How will I map previous set session-data with my own default settings.

For example, I have a filter list with different regions:
Quote: - NorthX
- SouthY
- Suburbs
- DownTown

When the user selects the checkbox in front of Suburbs and Downtown, we will set the session-variables in the controller accordingly :
Quote:$data['filter_list'] = array(
'N' => array ( 'name' => 'NorthX',
'show' => false) ,
'S' => array ( 'name' => 'SouthY',
'show' => false) ,
'SB' => array ( 'name' => 'Suburbs',
'show' => true),
'DT' => array ( 'name' => 'DownTown',
'show' => true)

Then, back in the view we can regenerate our checkboxes:
foreach ($filter_list as $filter_item) {

$data = array(
'name' => $filter_item['name'],
'id' => $filter_item['name'],
'value' => !$filter_item['show'], //invert the value we had.
'checked' => $filter_item['show'],
'style' => 'margin:1px',

echo form_checkbox($data);
echo $filter_item['name'];
echo "<br/>";

The question is, how do we map these things nicely back and forth (what if we add or remove filters, etc?).

Hope my question is somewhat clear.

Thanks in advance for any time I wasted Smile


I have the feeling my question is not clear enough.. is that the fact?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.