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

查看:167
本文介绍了如何让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),这不是问题。



这不是我有这个失败的唯一的例子,在几个其他项目类似的查询也会每次返回全部结果。



我已经阅读了所有文档,似乎有时甚至没有其他时间。任何人都有任何想法?



干杯

解决方案



唯一重要的是您使用 extend()返回的新对象。这样做的原因是, extend()创建一个新对象,该对象包装当前对象(Decorator模式)。



所以,你需要使用 $ query = $ query-> extend('PagerDefault'),就像你在你的答案(结合其他调用)一样。 p>

I'm running the following code:

$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();

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?

Cheers

解决方案

It is not relevant when you call 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).

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天全站免登陆