Please, I am getting crazy with the pagination class :( |
[eluser]victorche[/eluser]
Here is my model: Code: function get_posts($limit, $offset) And this is my controller: Code: function index($page = NULL) The links are generated normally, but anyway when I click on page 2, I always have 404 error ![]() Please, help! I've read 200 topics about it and still not success ![]()
[eluser]Althalos[/eluser]
I'm not a pro myself, but my guess is that it would work if you would put $config['base_url'] = site_url('articles/index'); I can see two things that could go wrong when you put $config['base_url'] = site_url('articles'); 1) The pagination class looks up the third URI segment by default. In your case, the page number would actually be second segment 2) The second segment normally is the method. So if you link to example.com/articles/2 instead of interpreting that as page two, it might look for a method called 2 and this might be what causes the 404.
[eluser]victorche[/eluser]
Thanks, really! This helped a little... You're right, now it works. Anyway it adds /index/ to the pagination links, something which I completely don't want to happen ![]() How should I do it, without adding $config['base_url'] = site_url('articles/index'); I want my pages to be site.com/articles/2 or site.com/articles/page:2 but without /index/
[eluser]Althalos[/eluser]
I believe you want to do this: http://ellislab.com/forums/viewthread/88534/
[eluser]Rolly1971[/eluser]
try adding a new route in application/config/route.php for the first style: route['articles/:num'] = 'articles'; if you use the second type: route['articles/:any'] = 'articles'; this will default a url like: http://site.com/articles/2 to the articles controller -> index function. so long as you have your index function reading and handling the uri segments properly this will work a charm
[eluser]victorche[/eluser]
Thanks a lot ... Adding a route rule fixed the problem :] Now another question (related with the topic) ... Can I have something like /articles/page:2 instead of just /articles/2 ?
[eluser]Althalos[/eluser]
I would suggest opting for a URL like this: example.com/articles/page/2/user/username And then in your controller, put this: $uri = $this->uri->uri_to_assoc(2); echo $uri['page']; //Echos "2" echo $uri['user']; //Echo "username"
[eluser]victorche[/eluser]
[quote author="Althalos" date="1280170813"]I would suggest opting for a URL like this: example.com/articles/page/2/user/username And then in your controller, put this: $uri = $this->uri->uri_to_assoc(2); echo $uri['page']; //Echos "2" echo $uri['username']; //Echo "username"[/quote] No, no ... articles part has nothing to do with users. Articles are submitted only by admins. I just want instead of only page number articles/2 to have a link like: articles/page:2 This makes more sense, as ... /articles/2 can mean like you are reading an article with id=2 but by adding page:2 it really makes sense.
[eluser]Althalos[/eluser]
I didn't give you a solution so that you didn't have to think. I gave you an example, so that you could understand one way to do what you wanted to do. The username part had a purely explanatory purpose. I understand why articles/page:2 is an improvement over articles/2, but articles/page/2 does exactly the same thing. It just looks a little bit different, but it is by far more common than separating values with :. Maybe this is why the format I suggested is supported in the URI class whereas the format you suggest is not. However, if you want to use your format you can still achieve this. It wouldn't be as beautiful a solution, but it'd work: $pageId = str_replcae('page:', '', $this->uri->segment(2)); |
Welcome Guest, Not a member yet? Register Sign In |