教条2和禅师 [英] doctrine 2 and zend paginator

查看:114
本文介绍了教条2和禅师的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆