Using Pagination with Get Vars? |
[eluser]Solarpitch[/eluser]
Hey Guys, I'm trying to use pagination with get vars instead of the segment based approach. My results page url looks something like: Code: http://www.mysite.com/?c=manager&m=client_list&sortby=name&page=2 The bit where I have page=2 doesnt work as I've modified the url to include this manually just to test. Instead of using the segment approach: Code: http://www.mysite.com/manager/client_list/2 -> page 2 of pagination I need to do it the get var way I have in the example, so my links: 1 2 3 NEXT ... would look like: http://www.mysite.com/?c=manager&m=clien...ame&page=1 http://www.mysite.com/?c=manager&m=clien...ame&page=2 http://www.mysite.com/?c=manager&m=clien...ame&page=3 etc
[eluser]Jondolar[/eluser]
I don't have an answer to your question but I was curious as to why you don't want to use the segment approach. I am working on my own project and was planning on using URI segments for both sort and page and I am curious as to why you chose not to? Did you run into problems? Good luck with your project.
[eluser]richwalkup[/eluser]
Check out the section of the documentation titled "Customizing the Pagination" and you'll see the following: Code: $config['page_query_string'] = TRUE; If you need to customize the query string parameter name, you can do that also. It's all documented in that section of the manual.
[eluser]Solarpitch[/eluser]
Hi richwalkup, I've already went through that a dozen times. It says: Note that "per_page" is the default query string passed, however can be configured using $config['query_string_segment'] = 'your_string' Thats all well and good but if I put: $config['query_string_segment'] = 'page' and then in my url I have: ...&page=2 ... noting happens. It wont paginate. This is where the problem lies. So when I click the pagination line (page 2 for example) what exactly do I pass into the url so that my controller can pick up the pagination page 2 and display that page of results? @jondolar: the reason I need to use this is because I have to be able to sort the results by various options.. first name, last name etc and CI segment approach doesnt really handle this well at all. For example: the sort variable wont always be segment 3 if there is a pagination page included in the url. It's tricky. get vars are they best way to handle this with CI.. unless I'm missing something.
[eluser]richwalkup[/eluser]
If you could post your pagination configuration it might help. It's very possible you're overlooking something very minor. What version of CI are you currently running? EDIT: I just realized you're using page=1, page=2, etc which is a problem. The number you are passing must be zero or a multiple of your "per_page" variable. If you are attempting to get to page 2 and you're listing 20 per page, your page 2 equivalent would be page=20.
[eluser]Solarpitch[/eluser]
Hi richwalkup, I dont have access to the code at the min unfortunately as it's a work project.. and I agree... it's probably something very minor. All I'm trying to do is use the pagination class without the uri segment approach. I just need to know how I get the page number from the url after the user clicks a pagination link. The code works fine from a segment approach. I've set $config['page_query_string'] = TRUE;
[eluser]Solarpitch[/eluser]
I should mention that this works fine: Code: http://www.mysite.com/?c=manager&m=client_list&sortby=name&per_page=10 This will update the result set and display 10 results per page. But if I try Code: http://www.mysite.com/?c=manager&m=client_list&sortby=name&per_page=10&page=3 it wont display page 3 of the pagination..
[eluser]richwalkup[/eluser]
If all you need is the querystring page number, you can use the Input library or simply use the PHP $_GET variable. Code: $qs_page = $this->input->get('page'); If you want to get the page number that the Pagination library thinks it should be using, you can do this: Code: $pl_page = $this->pagination->cur_page; I guarantee your biggest problem is related to the page numbers not being based off your 'per_page' variable though. In Pagination.php line 164, the code reads: Code: $this->cur_page = floor(($this->cur_page/$this->per_page) + 1); Using this formula (and assuming pages of 20 per), anything under 20 would resolve to page 1 and so on. So your literal page 1 should have a querystring value of 0, literal page 2 a value of 20, literal page 3 value of 60, etc. |
Welcome Guest, Not a member yet? Register Sign In |