doctrine 2 and zend paginator(学说 2 和 Zend 分页器)
问题描述
我想在 zend_paginator 中使用学说
i want to use doctrine with zend_paginator
这里有一些示例查询:
$allArticleObj =$this->_em->getRepository('文章');$qb = $this->_em->createQueryBuilder();
$allArticleObj = $this->_em->getRepository('Articles'); $qb = $this->_em->createQueryBuilder();
$qb->add('select', 'a')
->add('from', 'Articles a')
->setFirstResult(0)
->setMaxResults(5);
是否有任何示例代码表明我们可以为 Dotct 2 查询构建器编写 zend_paginator 适配器?
is there any example code to show we can write a zend_paginator adapter for doctrine 2 query builder?
推荐答案
结果当然是你必须实现Zend_Paginator_Adapter_Interface,这实质上意味着实现两个方法:
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)
您的适配器将接受 Doctrine 查询作为构造函数参数.
Your adapter would accept the Doctrine query as a constructor argument.
原则上,getItems() 部分实际上很简单.只需将 $offset 和 $perPage 限制添加到查询中 - 正如您在示例中所做的 - 并执行查询.
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.
在实践中,count() 业务往往很棘手.我会遵循 Zend_Paginator_Adapter_DbSelect 的例子,用它们的 Doctrine 类似物替换 Zend_Db 操作.
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 和 Zend 分页器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:学说 2 和 Zend 分页器
基础教程推荐
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- php中的PDF导出 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php中的foreach复选框POST 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
