我编写了通用脚本来获取Doctrine Table Models中的所有行,但是如果行数量太大,我会得到异常:
Cannot define NULL as part of query when defining 'offset'.
运行脚本:
$table = new JV_Model_StoreOrder();
$this->data['list'] = $table->getTable()->findAll()->toArray();
我从上面的错误中理解是由于表中的大量条目(> 20 000)。所以我决定制作一个分页器来打破100个页面上的记录。
你能帮助我吗,我该怎么办呢?
...
$total_amount = $table->getTable()->count();
$this->data['list'] = $table->getTable()->offset(0)->limit(100)
->findAll()->toArray();
...
答案 0 :(得分:1)
Doctrine拥有自己的分页组件:
Doctrine手册中的示例:
// Defining initial variables
$currentPage = 1;
$resultsPerPage = 50;
// Creating pager object
$pager = new Doctrine_Pager(
Doctrine_Query::create()
->from( 'User u' )
->leftJoin( 'u.Group g' )
->orderby( 'u.username ASC' ),
$currentPage, // Current page of request
$resultsPerPage // (Optional) Number of results per page. Default is 25
);