In cakephp framework there is a way which features pagination easily on your web page.
This can be done as :
Controller Code :
public $components = array('Paginator','Flash');
public function index() {
$this->paginate = array(
'limit' => 5,
'order' => array('id' => 'asc')
);
$pots = $this->paginate('Post');
$this->set('Posts', $posts);
$this->Post->recursive = 0;
$this->set('posts', $this->Paginator->paginate());
}
In the controller we have defined the paginate component as public $components = array('Paginator','Flash');
then we have included the conditions in the index function where we have limited the post to 5 with 'limit' => 5, and assigned in ascending order 'order' => array('id' => 'asc'), we can also make a condition which wont include a particular ID in post it can be done as by (conditions => array(User.id != => 6)).
Index Code :
In the index.ctp the data is presented. The presentation is done in table.
$this->Paginator has many functions for paging. the code for the pagination is as :
<?php
echo $this->Paginator->counter(array(
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
));
?> </p>
<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>
In this way we can apply Pagination to limit the number of posts on the presentation page.
0 Comment(s)