开发者

php paging class

开发者 https://www.devze.com 2022-12-23 18:32 出处:网络
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)

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 P开发者_JAVA百科ropel pager, to get it to do the things I listed about - please let me know.


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!


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


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 !

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号