php分页类
谁能推荐一个好的PHP分页类吗?
我搜索过谷歌,但没有看到任何符合我要求的东西。我决定先在这里登记,而不是“自己动手”(几乎肯定是重新发明轮子)。
首先是一些背景知识:
我正在 Ubuntu 9.10 上使用 Symfony 1.3.2 和 Propel ORM 开发一个网站。我目前正在使用 Propel 寻呼机,这还可以,但我最近开始使用 memcache 来加快速度。此时,Propel 分页器没什么用处,因为它(据我所知)仅适用于 Propel 对象。
我需要的是一个类 th:t 满足以下要求
具有干净的接口,关注点分离,以便从数据源(例如数据库)检索记录的逻辑封装在一个类(或至少一个单独的类)中文件)。
可以使用对象数组
提供分页链接,并且仅获取当前页面所需的数据。此外,如果可用页面链接太多,分页应该“拆分”。例如,如果可能有 1000 个页面链接,则显示的页面应类似于 FIRST 2,3 ....999 LAST
可以返回正在查询的表中所有记录的数量,以便以下链接可用FIRST, LAST(这个要求实际上已经在前面的要求中涵盖了 - 但我只是想再次强调一下)。
如果他们过去成功使用过的话,有人可以推荐这样的库吗?
或者,某些人可能“破解”(例如衍生自)当前的 Propel 寻呼机,以使其执行我列出的操作 - 请让我知道。
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
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).
Can work with arrays of objects
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
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不确定这是否符合要求,但 sfPropelPager 和 sfDoctrinePager 都从 sfPager 类,它提供向前/向后运动和分页等。您应该能够直接使用 sfPager,或者以与 Doctrine 和 Propel 相同的方式扩展它,使用元素数组来提供分页。
通常,由于这看起来是一个“非标准”用例,Symfony 网站上除了 API 文档外,关于它的文档为零,但 API 文档看起来相当全面,而且我确信 Doctrine/Propel 示例将能够引导您走向正确的方向!
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!
我一直在使用并推荐 PEAR::Pager 包,它能够完成您的任务需要。
I've been using and recommend the PEAR::Pager package which is able to do what you need.
您需要深入了解 sfPropelPager(或直接 sfPager)代码,了解其内部工作原理、在何处使用动态数据以及如何使其与 memcache 一起工作。
我不知道memecached,但你不能直接缓存propel记录吗? (我知道它们很大:D)
我的回答一点一点:
1:sfPager 与数据库无关,因为 sfDoctrinePager 和 sfPropelPager 都使用它,您可以将它用于工作和测试的基础。
2:sfPager 应该与数组一起使用,其中引用的模型类属性不在任何地方使用。 cf 来源
3:提供分页链接反对关注点分离,它对对象进行分页,并在其他地方生成链接(查看文件、帮助程序等)。
您可以根据需要显示它们,而无需修改寻呼机类或其后代
4:第一次和最后一次访问由 sfPager 类提供
我知道我听起来像 symfony 传教士,但这是我们通常使用这样的框架进行工作的方式。正如您所写,不要重新发明轮子!
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 !