![]() |
Pagination 404 on Page 2 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Pagination 404 on Page 2 (/showthread.php?tid=17185) |
Pagination 404 on Page 2 - El Forum - 03-28-2009 [eluser]gscharlemann[/eluser] I'm getting a 404 Page Not Found error when attempting to use pagination. I think it's in the way that I'm sending the base_url to Pagination, but I can't seem to figure out the correct way to specify it. The pagination class is also showing all results from the DB, it's not stopping the results after the "per_page" specification. Here's some code: Controller: file located in application/controller/contact/contact.php Code: class Contact extends Controller { View: file located in: application/views/contact/display_contact.php Code: <table> Page 1 displays all of the results from the database. Page 2 link gets a 404 error (http://www.mysite.com/index.php/contact/contact.html/2) - the config file is setup to put '.html' at the end of the url. My questions are as follows: 1. what URL should I specify as base_url. I've also tried Code: site_url("contact/display_contacts"); 2. what am I doing wrong in the view? how do I get the pagination to work with $contact_array? Thanks in advance for reading this and providing feedback! Pagination 404 on Page 2 - El Forum - 03-28-2009 [eluser]xwero[/eluser] You need routing the way you want it done Code: $route['(contact)/(\d+)'] = '$1/index/$2'; Pagination 404 on Page 2 - El Forum - 03-28-2009 [eluser]gscharlemann[/eluser] Xwero, thanks for the quick reply. I put the first line in the routes.php config file and the second two in the controller. Unfortunately, it didn't work. but I think if I can better understand what you are trying to do I can figure it out. What exactly does the Code: $route['(contact)/(\d+)'] = '$1/index/$2' I'm not good at regular expressions. Pagination 404 on Page 2 - El Forum - 03-28-2009 [eluser]xwero[/eluser] You want to paginate the index function but because CI fetches the second segment as the controller method you can't make it the pagination segment without routing. (contact) grabs the controller name and (\d+) grabs the digits after the forward slash, $1 and $2 are the placeholders for the grabbed values. What is wrong after you added my changes? Pagination 404 on Page 2 - El Forum - 03-28-2009 [eluser]gscharlemann[/eluser] After adding your changes, I still get the 404 error and the URL looks like: http://www.mysite.com/index.php/contact.html/2 The controller is located within a folder labeled contact, so I think the URL should be: http://www.mysite.com/index.php/contact/contact.html/2 I need to learn more about route and uri helpers. i also realized that all of the values are displaying because I'm not sending the limit and offset to the database query in the model. So if my limit per page is 10 and I get to page 2, my limit will be 20 and offset 10, correct? Pagination 404 on Page 2 - El Forum - 03-28-2009 [eluser]gscharlemann[/eluser] Thanks for the help. I've successfully implemented pagination. It's probably not as "clean" as it could be, but I modified the controller method to the following: Code: // needed to define what page to view. $index is set to default to The View (display_contacts.php): Code: <table> the problem I experience now is when I go to page 2, the correct results are returned, but the pagination links created at the bottom, do not reflect being on page 2. It still says I'm on page 1. Any thoughts as to why? How do I tell the links, which page we are on? Pagination 404 on Page 2 - El Forum - 03-28-2009 [eluser]gscharlemann[/eluser] scratch that... links are working correctly. Pagination 404 on Page 2 - El Forum - 06-26-2009 [eluser]unsub[/eluser] I have a follow up question to this - I have just put in the routing: Code: $route['process/:num'] = "process/browse/:num"; It's working for me, but now I am curious if that is just fluke, and I should be doing it like what you posted. Can you enlighten me as to what the differences are, and / or any reasons that I should change it? Yes, it works, but I would rather take the time to make it better if I can. Thanks very much |