如何在不加载数据库所有结果的情况下使用zend paginate [英] how to use zend paginate without loading all the results of a database

查看:88
本文介绍了如何在不加载数据库所有结果的情况下使用zend paginate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我看到zend分页工作的方式是:

So the way I see zend paginate work is that you do:

$paginator = Zend_Paginator::factory($results);
$paginator->setItemCountPerPage($itemCount);
$paginator->setPageRange($pageRange);

$ results是从数据库中以

Where $results is the result of loading a bunch of items from a database in the form of

"SELECT * FROM table WHERE etc"

然后zend分页器将计算结果数并自动生成页面范围...

Then zend paginate will count the number of results and generate the page ranges automatically...

但是,如果执行此操作,则将必须获取数据库的所有结果,我认为这是浪费,因为一次仅显示一页,因此只需要获取该页面的项目. ..

But if you do this then you're going to have to fetch all results of a database which I see as a waste since only one page is displayed at a time and therefore you only need to fetch the items for that page...

您如何使zend paginate能够计算正确的页面范围和数字而又不求取整个表的所有结果?

how do you make zend paginate to be able to calculate the correct page ranges and numbers without resorting to fetching all the results of an entire table?

推荐答案

使用工厂方法,您可以发送Zend_Db_Select或Zend_Db_Table_Select的实例.如果您是扩展Zend_Db_Table_Abstract的类,则可以简单地从中构建一个选择查询,然后将其发送.如果没有,您可以创建一个实例并发送它,请参阅文档中的示例:

Using the factory method you can send an instance of Zend_Db_Select or Zend_Db_Table_Select. If you're class extends Zend_Db_Table_Abstract you can simply build a select query from it and then send this. If not you can create an instance and send it, see the example from the docs:

    $adapter = new Zend_Paginator_Adapter_DbSelect($db->select()->from('posts'));
    $adapter->setRowCount(
        $db->select()
           ->from(
                'item_counts',
                array(
                   Zend_Paginator_Adapter_DbSelect::ROW_COUNT_COLUMN => 'post_count'
                )
             )
    );

$paginator = new Zend_Paginator($adapter)

http://framework. zend.com/manual/zh-CN/zend.paginator.usage.html#zend.paginator.usage.dbselect

这篇关于如何在不加载数据库所有结果的情况下使用zend paginate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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