How do I get PagerDefault queries to work correctly with Drupal 7?(如何让 PagerDefault 查询与 Drupal 7 一起正常工作?)
问题描述
我正在运行以下代码:
$query = db_select('taxonomy_index', 'ti')
->fields('ti', array('nid'))
->condition('ti.tid', $term->tid)
->condition('n.status', 1);
$query->join('node', 'n', 'n.nid = ti.nid');
$query->extend('PagerDefault')->limit(2);
$nids = $query->execute()->fetchCol();
但是寻呼机不起作用:查询中的每个项目都被返回,就好像对 PagerDefault 的调用被完全忽略了一样.我在输出中进一步输出主题('pager'),所以这不是问题.
but the pager does not work: every item from the query is returned, as if the call to PagerDefault is completely ignored. I am outputting theme('pager') further down in the output so that's not the problem.
这不是我遇到的这种失败的唯一例子,在其他几个项目中,类似的查询也每次都带回全部结果.
This is not the only example of this failure that I have, in several other projects similar queries also bring back the full number of results every time.
我已阅读所有文档,它似乎有时有效,有时无效.有人有什么想法吗?
I've read all the documentation, it seems to work sometimes and not other times. Anyone got any ideas?
干杯
推荐答案
什么时候调用 extend()
是不相关的.
唯一重要的是您使用了 extend()
返回的新对象.这样做的原因是 extend()
创建了一个包装当前对象的新对象(装饰器模式).
The only thing that is important is that you use the new object returned by extend()
. The reason for this is that extend()
creates a new object which wrappes the current object (Decorator pattern).
因此,您需要使用 $query = $query->extend('PagerDefault')
,就像您在回答中所做的那样(与其他调用相结合).
So, you need to use $query = $query->extend('PagerDefault')
, like you do in your answer (combined with other calls).
这篇关于如何让 PagerDefault 查询与 Drupal 7 一起正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何让 PagerDefault 查询与 Drupal 7 一起正常工作?


基础教程推荐
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 使用 PDO 转义列名 2021-01-01