Welcome Guest, Not a member yet? Register   Sign In
How do you make pagination with search, sort by, order by and limit work?
#2

[eluser]Kinsbane[/eluser]
I would honestly set up a custom route in your config/routes.php file that sends certain kinds of search queries to certain kinds of controllers so you can control exactly how the data goes through your system.

I don't have a searching method, but I did build a documents library for my company and this is how I handled all the different things (including pages, ASC/DESC, and sort by/order by. This is an example of my routes file:
Code:
$route['documents/case-studies'] = 'documents/casestudies/index/all/0/last_modified/DESC';
$route['documents/case-studies/(:any)/(:num)/(:any)/(:any)'] = "documents/casestudies/index/$1/$2/$3/$4";
$route['documents/case-studies/fiber-driver'] = "documents/casestudies/index/fiber-driver/0/last_modified/DESC";
$route['documents/case-studies/lambda-driver'] = "documents/casestudies/index/lambda-driver/0/last_modified/DESC";
$route['documents/case-studies/lx-series'] = "documents/casestudies/index/lx-series/0/last_modified/DESC";
$route['documents/case-studies/media-cross-connect'] = "documents/casestudies/index/media-cross-connect/0/last_modified/DESC";
$route['documents/case-studies/pluggables'] = "documents/casestudies/index/pluggables/0/last_modified/DESC";
$route['documents/case-studies/optiswitch'] = "documents/casestudies/index/optiswitch/0/last_modified/DESC";
$route['documents/case-studies/optiswitch-mr'] = "documents/casestudies/index/optiswitch-mr/0/last_modified/DESC";
$route['documents/case-studies/terescope'] = "documents/casestudies/index/terescope/0/last_modified/DESC";
$route['documents/case-studies/service'] = "documents/casestudies/index/service/0/last_modified/DESC";
$route['documents/case-studies/management'] = "documents/casestudies/index/management/0/last_modified/DESC";

As far as pagination goes, I actually had to modify the stock Pagination library that came with CI in order to include how the user is sorting, and by what they are sorting. Sample function:
Code:
function browse($family, $offset, $sortby, $sorthow)
{
$data['sorthow'] = ( $sorthow == "ASC" ) ? "DESC" : "ASC";
$data['offset'] = $offset;
$data['sortby'] = $sortby;
$docs = $this->docs->getDocuments('application-notes', $family, $this->num, $offset, $sortby, $sorthow);

//the following variables pertain to columns in the table, the headers, that the user can click on to change the sort:
$data['sort1url'] = $this->config->item('base_url').'documents/application-notes/'.$family.'/'.$offset.'/title/'.$data['sorthow'];
        $data['sort2url'] = $this->config->item('base_url').'documents/application-notes/'.$family.'/'.$offset.'/content_type/'.$data['sorthow'];
        $data['sort3url'] = $this->config->item('base_url').'documents/application-notes/'.$family.'/'.$offset.'/last_modified/'.$data['sorthow'];
//sorting by content type, title, and when the entry was last modified


//and finally set up the pagination
$config['uri_segment'] = 4; //I've made my program so that I always know the pagination segment will be 5
$config['base_url'] = $this->config->item('base_url').'documents/application-notes/'.$family;
$config['total_rows'] = count($this->docs->getTotalDocuments('application-notes', $family));
$config['per_page'] = $this->config->item('per_page_count');
$this->pagination->initialize($config);
$data['pages'] = $this->pagination->create_links('/'.$sortby.'/'.$sorthow); //I'm passing in my $sortby and $sorthow to the Pagination class so those values can be added to the paging numbers by the Pagination library

Now, I understand this has nothing to do with searching - but I think you're on the right path and I hope what I've posted can give you some ideas or inspiration on where to go.

I see you got the error regarding the disallowed characters - another option is to temporarily store the search term in a hash string and use that


Messages In This Thread
How do you make pagination with search, sort by, order by and limit work? - by El Forum - 05-18-2010, 12:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB