Welcome Guest, Not a member yet? Register   Sign In
Changing filter settings - combining http-post values, session-values, and default-values
#1

[eluser]mr.zeno[/eluser]
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)
$this->session->set_userdata($data['filter_list'])

Then, back in the view we can regenerate our checkboxes:
Quote:PSEUDO CODE:
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


Cheers!
Zeno.
#2

[eluser]mr.zeno[/eluser]
I have the feeling my question is not clear enough.. is that the fact?
#3

[eluser]mr.zeno[/eluser]
no-one?




Theme © iAndrew 2016 - Forum software by © MyBB