Showing a limited number of records per page has been a basic part of each application and it is very difficult task to bring out. CakePHP provides a easy way for limiting record to be display or for paginate data.
The PaginatorHelper gives us a easy and great solution for pagination data. Aside from pagination, it also have simple to use sorting highlights.
For implementing pagination we have to put below simple code into our controller.
public $paginate = [
'limit' => 5, // by this only 5 number of records should be display in a single page.
'order' => [
'Users.id' => 'asc'
]
];
Then we have to put below code in that function where we want to display data.
public function detail() {
$result=$this->paginate('User');
$this->set('registers',$result);
}
Then we have to add following code in our view.
<?php echo $this->Paginator->numbers(); ?>
<?php echo $this->Paginator->prev(' Previous', null, null, array('class' => 'disabled')); ?>
<?php echo $this->Paginator->next('Next ', null, null, array('class' => 'disabled')); ?>
<?php echo $this->Paginator->counter(); ?>
0 Comment(s)