php - Persist filter values in codeigniter with pagination library -


i use default codeiginter pagination library. tried implementing in created page shows vacancies, since getting many on site, performance terrible. why need pagination on page. note not cleanest solution, there new track going on overhauls entire page , starts scratch. quick & dirty solution because need keep working on our live environment until rework done.

this controller code have:

public function overviewvacancies($city = null) {     $this->is_logged_in();      // load models     $this->load->model('vacancy/vacancies_model');     $this->load->model('perk/interests_model');     $this->load->model('perk/engagement_model');     $this->load->model('user/usersavedvacancies_model');      // passing variables     $data['title'] = lang("page_title_activities_overview");     $data['description'] = lang('meta_desc_activities');     $data['class'] = 'vacancy';     $data['engagements'] = $this->engagement_model->getall();     $data['interests'] = $this->interests_model->getallinterests();     $data['bread'] = $this->breadcrumbmanager->getdashboardbreadcrumb($this->namemanager->getdashboardbreadname("0"), $this->namemanager->getdashboardbreadname("1"));     $data['tasks'] = $this->interests_model->getalltasks();      // set session data     $this->session->set_userdata('previous',"http://$_server[http_host]$_server[request_uri]");     $this->session->set_userdata('previous-title', "1");      $filterdata = array(         'interests' => $this->input->post('interests'),         'skills' => $this->input->post('skills'),         'fulldate' => $this->input->post('daterange'),         'location' => $this->input->post('location'),         'city' => $this->input->post('sublocality_level_1'),         'capital' => $this->input->post('locality')     );     if (!empty($filterdata['interests'])) {         $filterdata['interests'] = rtrim($filterdata['interests'], ";");         $filterdata['interests'] = str_replace(' ', '', $filterdata['interests']);         $filterdata['interests'] = str_replace(';', ',', $filterdata['interests']);     }     if (!empty($filterdata['skills'])) {         $filterdata['skills'] = str_replace(' ', '', $filterdata['skills']);         $filterdata['skills'] = explode(",", $filterdata['skills']);     }     //manually clear commune , city variables if location empty     if (empty($filterdata['location'])) {         $filterdata['city'] = '';         $filterdata['capital'] = '';     }      if($city == null){         $orgid = $this->organization_model->getorgidbyname(location);     }     else{         $orgid = $this->organization_model->getorgidbyname($city);         $data['bread'] = $this->breadcrumbmanager->getlocalbreadcrumb($this->namemanager->getdashboardbreadname("0"), $city, $data['title'], $data['vacancydetails']);     }      //set location subdomain automatically (e.g. when link clicked) activities of subdomain show     if (!empty(location)) {         $data['title'] = sprintf(lang('page_title_local_activities'), ucwords(location));         $data['description'] = sprintf(lang('meta_desc_local_activities'), ucwords(location));         $filterdata['location'] = location;         $data['bgcolor'] = $this->localsettings_model->getbgcolorhexvaluefororgid($orgid->org_id);     }      if (!empty($filterdata['fulldate'])) {         $splitfromandto = explode(" - ", $filterdata['fulldate']);         $filterdata['datefrom'] = $splitfromandto[0];         $filterdata['dateto'] = $splitfromandto[1];     } else {         $filterdata['datefrom'] = null;         $filterdata['dateto'] = null;     }      //put these variables in data variable can prefill our filters again previous values     //this necessary because don't use ajax yet     $data['filterdata'] = $filterdata;      //pagination : here can re-use filter query count our results     $this->load->library('pagination');     $data['all_vacancies'] = $this->vacancies_model->getfilteredvacancies($filterdata);     $pagconfig['base_url'] = base_url().vacancy_overview;     $pagconfig['total_rows'] = count($data['all_vacancies']);     $pagconfig['per_page'] = 1;     $pagconfig['uri_segment']  = 2;     $pagconfig['use_page_numbers'] = true;     $this->pagination->initialize($pagconfig);     $data['links'] = $this->pagination->create_links();     $start = max(0, ( $this->uri->segment(2) -1 ) * $pagconfig['per_page']);      //this variable contains data necessary vacancy displayed on vacancy overview page     $data['vacancies'] = $this->vacancies_model->getfilteredvacancies($filterdata, false, null, false, null, false, false, $pagconfig['per_page'], $start);      // template declaration     $partials = array('head' => '_master/header/head', 'navigation' => '_master/header/navigation_dashboard', 'content' => 'dashboard/vacancy/overview', 'footer' => '_master/footer/footer');     $data['vacancygrid'] = $this->load->view('dashboard/vacancy/vacancygrid', $data, true);     $this->template->load('_master/master', $partials, $data); } 

as can see in code keep variable called $filterdata, contains data used in our filters, since don't use ajax in version, need pass view every time fill again , present visitor. however, using pagination breaks because reloads controller method , values in $filterdata lost.

how go this?

note: not have clean solution, needs work since page going offline in couple of weeks anyway.

thanks lot in advance!


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -