Cake php provide inbuilt pagination we can use this by using Paginator Helper. To use pagination first we need to use Paginator Component
public $components = array('Paginator','Auth');
now add the below code in your controller here i am using pagination for users table
public function index() {
$this->User->recursive = 0;
$this->set('users', $this->Paginator->paginate());
}
now in your view add below code
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th><?php echo $this->Paginator->sort('id'); ?></th>
<th><?php echo $this->Paginator->sort('username'); ?></th>
<th><?php echo $this->Paginator->sort('password'); ?></th>
<th><?php echo $this->Paginator->sort('group_id'); ?></th>
<th><?php echo $this->Paginator->sort('created'); ?></th>
<th><?php echo $this->Paginator->sort('modified'); ?></th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo h($user['User']['id']); ?> </td>
<td><?php echo h($user['User']['username']); ?> </td>
<td><?php echo h($user['User']['password']); ?> </td>
<td><?php echo h($user['User']['group_id']); ?> </td>
<td><?php echo h($user['User']['created']); ?> </td>
<td><?php echo h($user['User']['modified']); ?> </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="paging">
<?php
echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
echo $this->Paginator->numbers(array('separator' => ''));
echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
?>
</div>
Now you can see your data with pagination with sorting functionality
0 Comment(s)