教条2和禅师 [英] doctrine 2 and zend paginator
问题描述
我想用zend_paginator使用原则
这里有一些示例查询:
$ allArticleObj =
$ this - > _ em-> getRepository('Articles');
$ qb = $ this - > _ em-> createQueryBuilder();$ qb-> add('选择','a')
- > add('from','Articles a')
- > setFirstResult(0)
- > setMaxResults(5);
是否有任何示例代码显示我们可以编写一个zend_paginator适配器for doctrine 2 query builder?
当然,结果是你必须实现 Zend_Paginator_Adapter_Interface
,其实质上是实现两种方法:
count()
p>
getItems($ offset,$ perPage)
您的适配器将接受作为构造函数参数的Doctrine查询。
原则上, getItems()
部分实际上是简单的。只要在查询中添加 $ offset
和 $ perPage
限制,就像您在样本中所做的那样,并执行查询。
在实践中,这是 count()
业务往往是棘手的。我会按照 Zend_Paginator_Adapter_DbSelect
的例子,用 Doctrine c替换
Zend_Db
code>类似物。
i want to use doctrine with zend_paginator
here some example query :
$allArticleObj = $this->_em->getRepository('Articles'); $qb = $this->_em->createQueryBuilder();
$qb->add('select', 'a') ->add('from', 'Articles a') ->setFirstResult(0) ->setMaxResults(5);
is there any example code to show we can write a zend_paginator adapter for doctrine 2 query builder?
The upshot, of course, is that you have to implement the Zend_Paginator_Adapter_Interface
, which essentially means implementing the two methods:
count()
getItems($offset, $perPage)
Your adapter would accept the Doctrine query as a constructor argument.
In principle, the getItems()
part is actually straightforward. Simply, add the $offset
and $perPage
restrictions to the query - as you are doing in your sample - and execute the query.
In practice, it's the count()
business that tends to be tricky. I'd follow the example of Zend_Paginator_Adapter_DbSelect
, replacing the Zend_Db
operations with their Doctrine
analogues.
这篇关于教条2和禅师的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!