I lost my post twice on post, so I’ll keep it short.
2 controllers: Search and Result, 2 views: for search form and results table, and one model for my offers.
Search is just search form with fields you have to fill for filter - nothing unusual. It redirects to result/prepare_sell (for sell offers or prepare_X for other type X)
Snippet for prepare_sell:
// get all input params (here I show just 4 for example)
$min_area = $this->input->post('min_area');
$max_area = $this->input->post('max_area');
$min_price = $this->input->post('min_price');
$max_price = $this->input->post('max_price');
// add them to array
$search_params = array(
'min_area' => $min_area,
'max_area' => $max_area,
'min_price' => $min_price,
'max_price' => $max_price);
// serialize them in JSON format
$ser = serialize($search_params);
// add them to sessions database
$session_record = array(
'query_text' => $ser,
'search_date' => date('Y-m-d H:i:s')
);
$sess_id = $this->offers->add_search_session($session_record);
I’ve skipped all validations and most of the fields, but this is the algorithm I use.
we redirect to results/sell and pass the $sess_id as a param:
function sell($session_id = '') {
// get session from database via the session_id we pass
$session = $this->offers->get_search_session($session_id);
// set validation rules
$per_page = 20;
$base_url = site_url('results/sell/'. $session_id);
$config['uri_segment'] = 4;
$config['num_links'] = 12;
// deserialize text query and add parameters to session_record array
$ser = $session['query_text'];
$session_record = unserialize($ser);
// add the array in the flashdata and then just print fields in the view
$this->session->set_flashdata($session_record);
Note I use URI segment = 4 (site.com/result/sell/session/page), and so I have the session and the page in the URL.
Pagination I do setting offset in the URL and limit hardcoded in the config.