pagination beginner question |
[eluser]cehennem[/eluser]
Hi. I am trying to make a simple pagination test. Here is my default controller Code: <? And routes Code: $route['page/(:num)'] = "main_page/index/page/$1"; index.php is located under /test/ Now everything works ok on all pages page/1 page/2 etc. But when I go http://localhost/test/page/ (no page specified) I get 404 Not Found. I think here 'page' becomes a function name which does not exists. I want 1st page to be shown if no page specified like ..com/test/page/ I've tried to route it but couldn't success. Thanks guys.
[eluser]Narkboy[/eluser]
Man - wrote an entire reply then realised that I'd misread. Your code is a little confusing for me. Basically - I avoid routing where possible. Let CI do the work. At the moment, your $route is saying: "a url with 'page/' then a number should be sent to the 'main_page' controller, should call the 'index' function, and that function should be given two variables - 'page' and the number in the url." Ok - but your function dosen't want 2 variables. It dosen't want any! If the index function only displays pagination, then you want: Code: function index($page_number) { And your route should be: Code: $route['page/(:num)'] = "main_page/index/$1"; Also, remember check that $page_number is exactly what you expect so that you don't get nasty security issues. Think that'll do it! /B |
Welcome Guest, Not a member yet? Register Sign In |