Reputation: 411
hi all I'm trying to have pagination in a table in one of my views, I have my find statement returning the correct set of results however I am unsure how I can make my table be able to sort the information I have found.
here is the controller, when I try paginate the find all i get is errors
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);
}
here is the code for the view
<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; ?>
Upvotes: 0
Views: 234
Reputation: 592
CakePHP reference for pagination in controller side as wee as on view side so it will give you deep knowledge in paginator of cakePHP
http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html http://book.cakephp.org/1.3/view/1233/Pagination-in-Views
example http://bakery.cakephp.org/articles/rtconner/2007/06/13/basic-pagination-overview-1-2
Upvotes: 0
Reputation: 71908
You should call paginate
instead of find
, not after it:
$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);
Upvotes: 1