Pagination and routing |
[eluser]Skoobi[/eluser]
Hi im having slight issues trying to get the pagination to work. I think its because im using routes... Ive tried a few thing but i cant seem to get it to work... It doesn't seem to choose 5 posts it displays all of them and then if you click the next page it throws a 404. Heres the controller: Code: //------------------------------------------------------------------------------- Heres the model: Code: public function get_posts() and the routes: Code: $route['blog'] = "posts"; Any Ideas??? Cheers Chris
[eluser]Tpojka[/eluser]
You don't need to limit counting rows in model. You need to use same query as in get_posts() function with ending num_rows() in your model so you will get correct $postCount value. What is written down in link hover status bar when you move mouse onto next button?
[eluser]Skoobi[/eluser]
Hi cheers for your reply. Is this what you mean with the getposts? Model: Code: public function get_post_count() the hover link is http://my_site.com/blog/5
[eluser]CroNiX[/eluser]
I think one problem is here: Code: $route['blog/(:num)'] = "posts/$1"; So if you had a request for www.yoursite.com/blog/4, it would send it to "posts" controller and a method named "4", which obviously can't exist. So try adding the actual method in there like you did here: Code: $route['blog/(:any)'] = "posts/post/$1";
[eluser]Tpojka[/eluser]
First, in routes.php file you need: Code: $route['blog'] = "posts/index"; That argument should be used for counting offset. Check this video (it is 1.x.x. version of CI so there will be some code distinction). P.S. start at 3:00 minute.
[eluser]Skoobi[/eluser]
Guys!! Your absolute legends. This is why i love the codeigniter framework, people help! Many thanks |
Welcome Guest, Not a member yet? Register Sign In |