views:

446

answers:

3
+1  Q: 

php paging class

Can anyone recommend a good PHP paging class?

I have searched google, but have not seen anything that matches my requirements. Rather than "rolling my own" (and almost surely reinventing the wheel), I decided to check in here first.

First some background:

I am developing a website using Symfony 1.3.2 with Propel ORM on Ubuntu 9.10. I am currently using the Propel pager, which is OK, but I recently started using memcache to speed things up a little. At this point, the Propel pager is of little use, as it (AFAIK), only works with Propel objects.

What I need is a class th:t meets the following requirents

  1. Has clean interface, with separation of concerns, so that the logic to retrieve records from the datasource (e.g. database) is encapsulated in a class (or at least a separate file).

  2. Can work with arrays of objects

  3. Provides pagination links, and only fetches the data required for the current page. Also, the pagination should 'split' the available page links if there are too many. For example, if there are potentially 1000 possible page links, the pages displayed should be something like FIRST 2,3 ....999 LAST

  4. Can return the number of all the records in the table being queried, so that the following links are available FIRST, LAST (this requirement is actually already covered in the previous requirement - but I just wanted to re-emphasise it).

Can anyone recommend such a library, if they have used it succesfully in the past?

Alternatively, someobe may have 'hacked' (e.g. derived from) the current Propel pager, to get it to do the things I listed about - please let me know.

A: 

I've been using and recommend the PEAR::Pager package which is able to do what you need.

bpedro
Looks interesting. Will have to see what effort (if any) is required to get it to do what I want, AND to play nicely with Symfony
Stick it to THE MAN
+2  A: 

Not sure if this will fit the bill, but both sfPropelPager and sfDoctrinePager extend from the sfPager class, which provides forward/back motion and paging etc. You should be able to either use sfPager directly, or extend from it in the same way as Doctrine and Propel do with your array of elements to provide paging.

Typically, as this looks to be a "non-standard" use-case, there's zero docs on the Symfony site about it save for the API documentation, but the API docs look pretty comprehensive, and I'm sure the Doctrine/Propel examples will be able to guide you in the right direction!

richsage
richsage: I have voted up your answer. This is probably the way I will end up going (extending sfPager), if there are no off the shell classes available. I know there are pcakages like Pear etc, but to get it to do what I want it to do would be just as long as me extending the sfPager class - and at least I stay within the SF framework
Stick it to THE MAN
Thanks for the upvote :-) yeah that's what I was aiming at - the whole keeping-it-inside-symfony, particularly if there's a class you can use as a base!
richsage
A: 

You need to down into the sfPropelPager (or sfPager directly) code, understand how it works internally, where dynamic data is used and how you can get it working with memcache.

I don't know memecached but can't you cache propel records directly ? (I know they're huge :D)

My answer point by point :

1 : sfPager is DB agnostic as it is used by both sfDoctrinePager and sfPropelPager, you can use it for a working and tested base.

2 : sfPager should with work with arrays, the model class property referenced in it is not used anywhere. Cf source

3 : Providing pagination links is against separation of concerns, it paginates on objects and links are generated elsewhere (view file, helper, etc.). You can display them as you want without modyfing the pager class or its descendents

4 : First and last access are provided by sfPager class

I know I can sound like symfony preacher, but this is the way we usually od things working with such a framework. As you wrote, do not reinvent the wheel !

Benoit