分页助手输出不正确的结果 - cakephp

时间:2015-12-05 12:52:57

标签: php cakephp pagination

我有一个项目模型,其中包含许多发票和积分。我正在尝试在我的ProjectsController中对特定函数中的Invoices和Credits信息进行分页。

没有问题获得正确的信息分页:

App::Import('Model', 'Invoice');
$this->Invoice = new Invoice;
$this->Paginator->settings = array(
    'conditions' => array('Invoice.paid' => 1, 'Invoice.project_id'=>$id),
    'limit' => 5
);
$paidInvoices = $this->paginate('Invoice');

App::Import('Model', 'Credit');
$this->Credit = new Credit;
$this->Paginator->settings = array(
    'conditions' => array('Credit.project_id' => $id),
    'limit' => 3
);
$credits = $this->paginate('Credit');

问题在于,即使我在文档6页面中指定的模型也会显示链接:应该只有2个。即使可能没有可访问的页面,也总会有下一个链接。

echo '<div class="right pagination">'.$this->Paginator->first('<< first', array('model'=>'Credit')).
    $this->Paginator->prev('< ' . __('previous'), array('model'=>'Credit'), null, array('class' => 'prev disabled')).
    $this->Paginator->numbers(array('separator' => '', 'model'=>'Credit')).
    $this->Paginator->next(__('next', array('model'=>'Credit')) . ' >', array('model'=>'Credit'), null, array('class' => 'next disabled')).
    $this->Paginator->last('last >>', array('model'=>'Credit')).'</div>';

1 个答案:

答案 0 :(得分:0)

在计算可用结果的数量时,看起来CakePHP变得混乱。 $settings属性似乎是罪魁祸首。

您必须为模型名称包含密钥,如下所示:

    $this->Paginator->settings['Invoice'] = array(
        'conditions' => array('Invoice.paid' => 1, 'Invoice.project_id'=>$id),
        'limit' => 5
    );

    $this->Paginator->settings['Credit'] = array(
        'conditions' => array('Credit.project_id' => $id),
        'limit' => 3
    );