cakephp 1.3 对habtm相关数据进行分页
我已经四处搜索并尝试了多种不同的解决方案,但我似乎无法让它发挥作用。 基本上我有产品和类别。 类别具有并属于许多产品,并且产品为 HABTM 类别。它们显然在连接表 products_categories 中与 id、product_id、category_id 字段相关。
经过简单的完整烘焙后,模型视图和控制器被烘焙 - 添加了一些类别和产品并设置了它们的关系,我可以转到特定的类别视图页面,预烘焙视图将显示与此类别相关的产品。
然而,有相当多的产品(而且还会更多),我正在努力弄清楚如何对所有这些相关数据进行分页……因为仅仅简单地列出一个类别中的所有产品是不可行的(可能有100 秒或更多) 有人可以帮忙吗?似乎关于这个问题还有很多未解答的主题以及各种不同的解决方案,我都无法开始工作!请帮忙!
I have searched high and low and tried multiple different solutions to this and I cannot seem to get it to work.
Basically I have products and categories.
Categories has and belongs to many products, and products HABTM categories. They are obviously related in a join table products_categories with id,product_id,category_id fields.
After a simple full bake- models views and controllers are baked - some categories and products are added and their relationships are set I can go to a specific category view page and the pre baked view will show products that are related to this category.
However, there is quite a few products (and will be more) and I am struggling to work out how to paginate all of this related data..as it is unfeasible to just simply list all of the products in a category (there could be 100s or more)
Can anybody help? It seems there are quite a few unanswered topics on this and various different solutions, none of which I can get to work! Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CakePHP 控制器具有内置分页。该文档非常详尽,因此我建议您首先阅读该文档。之后,我很乐意回答您对此主题的任何问题。
在不知道所涉及的具体代码的情况下,以下是如何对模型数据进行分页的简单示例:
CakePHP controllers have built in pagination. The documentation is thorough, so I would recommend reading that first. Afterwards, I'd be happy to answer any questions you have on the subject.
Without knowing the specific code involved, here is a simple example of how to paginate your model data:
您应该阅读这篇文章 http://blog.sohaibmuneer.com/使用-mysql-inner-join-in-cakephp-pagination
您也可以在查找查询中使用 join http://book.cakephp.org /1.3/view/1047/连接表
You should read this article http://blog.sohaibmuneer.com/using-mysql-inner-join-in-cakephp-pagination
and also you can use join in your find query http://book.cakephp.org/1.3/view/1047/Joining-tables