Pagination |
[eluser]nCoder[/eluser]
Ok CI newbie here... Have probably rather simple question about paging. I have path that looks like this somesite.com/books/page/10 that url will show books (items), page 10, and works fine... BUT if books are divided in some categories let's say: horror, thriller, adventure, science, computing, biology ... etc (lots of those categories), how can I make pagination work with this. Is this good way of putting it: somesite.com/books/page/10?cat=science or maybee this: somesite.com/books/science/page/10 Or should I just save that category in session and read it from it whenever is needed? What are your best practices... Thanks!
[eluser]ciGR[/eluser]
Hello, CI newbie here too, but I'll make a try to help you. I believe that it's better to use this Code: somesite.com/books/science/page/10 Also don't forget to change the uri_segment option at pagination initialise, because here you have one more argument than Code: somesite.com/books/page/10 Hope to help you. :-)
[eluser]GSV Sleeper Service[/eluser]
I'd go for this one - somesite.com/books/science/page/10 makes it easier for your users to bookmark etc.
[eluser]nCoder[/eluser]
I know that this option looks best and is best for SEO but how to get it working, since I want both to work Code: somesite.com/books/page/10 Code: somesite.com/books/science/page/10 In first case segmet(3) is page number in second page number is segment(4) So I have to determine where's the page number in what segment... BUT According to the user guide: http://ellislab.com/codeigniter/user-gui.../urls.html segment 2 is function, in my case category name and CI will look for that function in controller. I have like 150 categories and I can't make 150 functions for all that categories. Even declaring all those functions would be madness... Is there any way around that?
[eluser]ciGR[/eluser]
As I said I am newbie to this too, so I'm not sure that the solutions I'll suggest works fine or if they are good practices. Ι think that you can use the _remap() function into the controller books.php. When the controller executed then always called the _remap function regardless what your URI contains. Next into the _remap function you will check the arguments and act according them, with methods which declared here. An other solution is to create other two method with name cat or category and all into the controller books.php and when you want to get from all the categories use the all() function into the controller with url like this Code: somesite.com/books/all/page/10 and when you want to get books from a category use the method category(or cat) with this way Code: somesite.com/books/cat/science/page/10
[eluser]nCoder[/eluser]
well... not quite... Url's are working displaying right content... but pagination is not working right... on normal page Quote:somesite.com/books/page/10pagination works righ but on subcategory page Quote:somesite.com/books/cat/science/page/10pagination is always on first page (bold is always on number 1) on matter what page do I click... PS I set up baseurl right Code: $config['base_url'] = 'http://www.somesite.com/find/books/science/page/';
[eluser]nCoder[/eluser]
Solved Once again I'm going to answer to my own question... Code: $config['uri_segment'] = 5;
[eluser]ciGR[/eluser]
I think that at base_url you must set the somesite.com/books/cat/science/page/ The $config['uri_segment'] is ok? Look at this tutorial http://godbit.com/article/pagination-with-code-igniter may help you. Edit. Ok then. I had't see your answer at #7. |
Welcome Guest, Not a member yet? Register Sign In |