0

大家好,我试图在我的一个视图中对表格进行分页,我的 find 语句返回了正确的结果集,但是我不确定如何让我的表格能够对我找到的信息进行排序。

这是控制器,当我尝试分页时发现我得到的只是错误

public function index_admin(){
    //displays all disputes related to account.id
    //in a dashboard for an administrator user

    $this->set('title_for_layout', 'Dispute');
    $this->set('stylesheet_used', 'homestyle');
    $this->set('image_used', 'eBOXLogoHome.png');
    $this->layout='home_layout';

    //gets the User.account_id
    $id = $this->Auth->User('account_id');
    $conditions=array("OR"=> array(
        'Invoice.sender_id' => $id,
        'Invoice.receiver_id' => $id));

    $receiver=$this->Dispute->find('all',array(
    'conditions'=>$conditions));

    $this->set('receiver',$receiver);
    $this->paginate('Dispute'); 
    $this->set('id',$id);


}

这是视图的代码

            <tr>
                <th><?php echo $this->Paginator->sort('id', 'Invoice ID'); ?></th>
                <th><?php echo $this->Paginator->sort('dispute_date', 'Dispute Created'); ?></th>
                <th><?php echo $this->Paginator->sort('status', 'Status'); ?></th>
                <th>Actions</th>
            </tr>

    <?php foreach($receiver as $receivers):?>

    <tr>
        </tr><tr>
        <td><?php echo $receivers['Invoice']['id'] ;?></td>
        <td><?php echo $receivers['Dispute']['dispute_date'] ;?></td>

    <?php

    if($receivers['Dispute']['active']==1)
    {
        $status = 'Active';
        $bgcol = '#B9FAEA';
    }
    else 
    {
        $status = 'Resolved';
        $bgcol = '#FAB9B9';
    } 
    ?><td align='center' bgcolor='<?php echo $bgcol ?>'><?php echo $status ?></td>
    <td><?php echo $this->Form->Html->link('View',
                                array('controller' => 'Messages','action'=>'viewMessage_admin',$receivers['Dispute']['id'])); ?>
                <?php echo $this->Form->Html->link('Resolve',
                                array('controller' => 'Disputes','action'=>'resolve',$receivers['Dispute']['id'])); ?></td>
    </tr>


<?php endforeach; ?>
4

2 回答 2

1

您应该调用paginate而不是find,而不是在它之后:

$id = $this->Auth->User('account_id');
$conditions=array("OR"=> array(
    'Invoice.sender_id' => $id,
    'Invoice.receiver_id' => $id));

$receiver=$this->paginate('Dispute', $conditions);
$this->set('receiver',$receiver);
$this->set('id',$id);
于 2012-09-25T00:55:01.363 回答
0

控制器端分页的 CakePHP 参考与视图端一样,因此它将让您深入了解 cakePHP 的分页器

http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html http://book.cakephp.org/1.3/view/1233/Pagination-in-Views

例如 http://bakery.cakephp.org/articles/rtconner/2007/06/13/basic-pagination-overview-1-2

于 2012-09-25T06:57:46.657 回答