如何让 PagerDefault 查询与 Drupal 7 一起正常工作?

2023-06-23php开发问题
2

本文介绍了如何让 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 一起正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17