在 Propel 分页中:查询与条件
我在 propel 中有这个查询,
$units = UnitQuery::create()->find();
我正在尝试对返回的结果进行分页,所以我想我需要使用 PropelPager,根据文档,它是这样创建的
$criteria = new Criteria();
$criteria->add(BookPeer::AUTHOR, $authorId);
$pager = new PropelPager($criteria, 'BookPeer', 'doSelect', $page = 1, $rowsPerPage = 30);
我不明白的是如何转换 1 行 $我通常使用的单位
查询,到$criteria
。
另外,有没有办法将 $units
等普通查询与 PropelPager
一起使用?这比更改查询以使用 $criteria
和 doSelect
等更容易。
I have this query in propel
$units = UnitQuery::create()->find();
I'm trying to paginate the results returned, so I guess I need to use PropelPager, which according to documentation is created like this
$criteria = new Criteria();
$criteria->add(BookPeer::AUTHOR, $authorId);
$pager = new PropelPager($criteria, 'BookPeer', 'doSelect', $page = 1, $rowsPerPage = 30);
What I don't understand is how to convert the 1 line $units
query that I usually use, to $criteria
.
Also, is there a way to use a normal query like $units
with the PropelPager
? It would be easier than changing the query to use $criteria
and doSelect
, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以简单地这样做:
如果你真的想使用自定义分页器(但你可能不想):
顺便说一句,Propel XXXQuery 类只是类固醇的标准;)
You can simply do this :
And if you really want to use a custom pager (but you probably don't) :
Btw, Propel XXXQuery classes are just Criteria on steroids ;)
paginate 方法创建的分页器是 PropelModelPager 的一个实例,它是与 PropelPager 完全不同的类(符合不同的接口)。
由于 Query 对象扩展了 Criteria,因此也可以使用 PropelPager,我发现这是必要的,因为我们使用 PropelPager 的子类,它添加了缓存等功能。
The pager created by the paginate method is an instance of PropelModelPager which is an entirely different class (conforming to a different interface) to the PropelPager.
As the Query object extends Criteria it is also possible to use the PropelPager which I found necessary as we use a child class of PropelPager which adds caching amongst other things.