zend框架中如何对两个表进行分页
图书具有以下字段
- book_id
- book_name
- book_auther
- book_pub_date
类别表有
- category_id
- Category_name
展示位置表有
- placement_idplacement_category_id
- (FK)
- placement_book_id(FK)
现在我们想在索引控制器中使用分页来 选择特定类别的书籍?
所有表都在一个数据库中
注意:我为每个表设置了单独的模型,并且所有表都通过 $_referenceMap 相互关联
我使用 $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
问题是:如何进行 $select ?
Books has the following fields
- book_id
- book_name
- book_auther
- book_pub_date
category table has
- category_id
- category_name
placement table has
- placement_id
- placement_category_id(FK)
- placement_book_id(FK)
Now we want to use pagination in index controller to
select books with specific category ?
all tables are in one database
Note: I have separated model for each table and all tables are related each other with $_referenceMap
I use $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
the question is : how to make $select ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
书籍和类别之间存在多对多关系,并且您的放置表是交集表。因此,我认为构建 $select 的一种方法是使用内部联接,如下所示:
当然,表和模型的名称必须与您的真实姓名匹配。
另一种方法是在数据库中创建视图。然后您将为视图创建一个模型。这将使 $select 更短。
You have many-to-many relationship between books and categories, and your placement table is an intersection table. Thus I think that one way your $select could be constructed is using inner join as follows:
Off course the names of tables and models must match your real names.
Another way would be to create a view in your database. Then you would create a model for the view. This would make the $select shorter.
您可以使用此分页类:
http://www .catchmyfame.com/2007/07/28/finally-the-simple-pagination-class/
设置和使用非常简单,然后将其应用于 JOINed 查询,该查询从特定的位置选择所有书籍类别(这里很多人会比我解释得更好)。
You can use this pagination class:
http://www.catchmyfame.com/2007/07/28/finally-the-simple-pagination-class/
it's really simple to setup and use, and then you apply it to a JOINed query which selects all the books from the specific category (which many here would explain better than me).