Welcome Guest, Not a member yet? Register   Sign In
Beginners quetion - how to implement pagination


first of all I have to apologize for my not so perfect english in advance. I am building a personal photoblog with use of codeigniter and I just got little bit stuck in implementing pagination.

I am using this type of navigation across my site:


"view" is the function in main controller and it accepts 3 parameters - on the top is the name of gallery (for example "nature"), then subgallery (for example "Alps") and the last one is photo_id.

I thought it will be good idea to use this "pseudo directory" structure, but then I found out it is not Wink If I want to separate pictures in a gallery or in a subgallery with use of pagination library, I have a problem because next URI segment is parameter of my function.

http://www.mysite.com/view/gallery/20 -> tries to load subgallery with name 20, which does not exist.

Any ideas how to implement pagination and still have pseudo-directory structure?


Hi jay.cz, and welcome to the CI forums.

There's a few ways you could approach this problem. Check the CI User Manual for any upper-case references I'm about to make.

You could look at ROUTES - these would let you re-write the URL on the way in. I think this might not be the best approach here, but I'm not a big proponent of routing as the answer to all problems.

You could look at having a sub-gallery by default even on galleries that don't have a sub-gallery. A reserved word that you set aside for this, and your controller would handle it as a special case. This would mean your pagination number will then consistently be at the same segment() number.

You could examine the first parameter in your controller's constructor, and if it is numeric you know you're dealing with a pagination offset for the default or primary gallery - if the first character is alpha then you know you're dealing with a sub-gallery. This is a variation on the route approach above, and is arguably messier (though it's probably the way I'd deal with the problem).

Finally, you could re-visit the approach of sub-galleries - unless you're relying on external data? Sub-galleries assume a single level of categorisation, which doesn't always work out.

Thank you for your hint! I think reserved word will do the job for me Smile

Theme © iAndrew 2016 - Forum software by © MyBB