如何让 PagerDefault 查询与 Drupal 7 一起正常工作? [英] How do I get PagerDefault queries to work correctly with Drupal 7?

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

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