简体   繁体   English

Zend 1分页器限制

[英]Zend 1 Paginator limit

I'm working with Zend 1 (1.12), and I'm using the Zend_Paginator class to display query results on a web-page. 我正在使用Zend 1(1.12),并且正在使用Zend_Paginator类在网页上显示查询结果。 However, there's a large number of records (over one million), and realistically, in most cases, they're only going to need or want to search through the most recent 1000 or so records. 但是,有大量的记录(超过一百万条),实际上,在大多数情况下,它们仅需要或想要搜索最近的1000条左右的记录。

The problem is, I already have part of the web-page setting the "per page" value, which inherently creates a limit (and offset, if they're no longer on 'page 1' of the search.) 问题是,我已经在网页的一部分中设置了“每页”值,这固有地创建了一个限制(以及偏移量,如果它们不再位于搜索的“页面1”上)。

Basically, what I'm asking is, is there any way to tell the Zend_Pagintor "only fetch the first 1000 records, and then paginate them based on the user's per page selection"? 基本上,我要问的是,是否有任何方法告诉Zend_Pagintor“仅获取前1000条记录,然后根据用户的每页选择对它们进行分页”?

I have tried passing in a limit parameter into the interface I'm using, but the Zend_Paginator seems to ignore that, fetches all results, and then paginates them. 我尝试将限制参数传递到我正在使用的接口中,但是Zend_Paginator似乎忽略了这一点,获取所有结果,然后对它们进行分页。

function getRecords($currentPage)
{
    $select = "select * from table where user_id = 1 limit 1000"; 
    /* $select is actually a Zend_Db_Table_Select object, not a string. */
    $paginator = new Zend_Paginator::factory($select);
    $paginator->setItemCountPerPage(25);
    $paginator->setCurrentPageNumber($currentPage);

    return $paginator;
}

(The $select is obviously a placeholder.) ($ select显然是一个占位符。)

Set total row count manually 手动设置总行数

$select = "select * from table where user_id = 1";
$paginator = new Zend_Paginator::factory($select);
$paginator->getAdapter()->setRowCount(1000);
...

Try creating SQL view from your limited query: 尝试从有限的查询中创建SQL视图:

CREATE OR REPLACE VIEW table_view AS
SELECT * 
FROM table 
WHERE user_id = 1 
LIMIT 1000

This view will return only rows you want (1000 rows in this case), then switch your Zend_Db_Table_Select to this view and create paginator like your getRecord method does. 该视图将仅返回所需的行(在这种情况下为1000行),然后将Zend_Db_Table_Select切换到该视图,并像getRecord方法一样创建分页器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM